aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-25 21:29:55 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-25 21:29:55 +0300
commit5a4580be41f7c5dd6ab650413a373008b7bceaa5 (patch)
tree3c90f96482e1b03fc5cd18766f149d54b049b2a9 /Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI
parentfbb0fc27c618e339d9771d9a7155d0ef69cf0218 (diff)
downloadTango-5a4580be41f7c5dd6ab650413a373008b7bceaa5.tar.gz
Tango-5a4580be41f7c5dd6ab650413a373008b7bceaa5.zip
Added file drop to log viewer.
Diffstat (limited to 'Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI')
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/LogViewerSettings.cs20
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj1
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs73
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml64
-rw-r--r--Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml.cs18
5 files changed, 154 insertions, 22 deletions
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/LogViewerSettings.cs b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/LogViewerSettings.cs
new file mode 100644
index 000000000..6d2545b32
--- /dev/null
+++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/LogViewerSettings.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.Settings;
+
+namespace Tango.FSE.LogViewer.UI
+{
+ public class LogViewerSettings : SettingsBase
+ {
+ public bool WrapLines { get; set; }
+ public List<String> RecentFiles { get; set; }
+
+ public LogViewerSettings()
+ {
+ RecentFiles = new List<string>();
+ }
+ }
+}
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj
index d78944d97..9c9e246e1 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj
+++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Tango.FSE.LogViewer.UI.csproj
@@ -61,6 +61,7 @@
<Compile Include="ArgsObject.cs" />
<Compile Include="Converters\PolygonTabToPointCollectionConverter.cs" />
<Compile Include="LoadFromTfsMode.cs" />
+ <Compile Include="LogViewerSettings.cs" />
<Compile Include="LogViewerViewModel.cs" />
<Compile Include="ViewModelLocator.cs" />
<Compile Include="ViewModels\LayoutViewVM.cs" />
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs
index 1a255fa9e..abc0e56aa 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/ViewModels/LayoutViewVM.cs
@@ -18,6 +18,7 @@ using Tango.Logging;
using ZetaIpc.Runtime.Server;
using Tango.TFS;
using System.Diagnostics;
+using Tango.Settings;
namespace Tango.FSE.LogViewer.UI.ViewModels
{
@@ -26,6 +27,8 @@ namespace Tango.FSE.LogViewer.UI.ViewModels
private ICollectionView _view;
private IpcServer _ipcServer;
+ private LogViewerSettings Settings { get; set; }
+
public ObservableCollection<LogFileTabViewVM> LogFiles { get; set; }
private LogFileTabViewVM _selectedLogFile;
@@ -42,18 +45,36 @@ namespace Tango.FSE.LogViewer.UI.ViewModels
set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); }
}
+ private bool _wrapLines;
+ public bool WrapLines
+ {
+ get { return _wrapLines; }
+ set { _wrapLines = value; RaisePropertyChangedAuto(); OnWrapLinesChanged(); }
+ }
+
+ private List<String> _recentLogFiles;
+ public List<String> RecentLogFiles
+ {
+ get { return _recentLogFiles; }
+ set { _recentLogFiles = value; RaisePropertyChangedAuto(); }
+ }
+
public RelayCommand OpenLogFileCommand { get; set; }
+ public RelayCommand<String> OpenRecentLogFileCommand { get; set; }
public RelayCommand<LogFileTabViewVM> CloseLogFileCommand { get; set; }
public RelayCommand SaveAsLogFileCommand { get; set; }
public RelayCommand ExitCommand { get; set; }
public LayoutViewVM()
{
+ WrapLines = true;
+ RecentLogFiles = new List<string>();
LogFiles = new ObservableCollection<LogFileTabViewVM>();
OpenLogFileCommand = new RelayCommand(OpenLogFile);
CloseLogFileCommand = new RelayCommand<LogFileTabViewVM>(CloseLogFile);
SaveAsLogFileCommand = new RelayCommand(SaveAsLogFile);
ExitCommand = new RelayCommand(ExitApplication);
+ OpenRecentLogFileCommand = new RelayCommand<string>(OpenRecentLogFile);
_ipcServer = new IpcServer();
Application.Current.MainWindow.ContentRendered += MainWindow_ContentRendered;
@@ -108,6 +129,20 @@ namespace Tango.FSE.LogViewer.UI.ViewModels
private async Task OpenLogFile(String file)
{
+ var existingLogFile = LogFiles.ToList().FirstOrDefault(x => x.File == file);
+
+ if (existingLogFile != null)
+ {
+ SelectedLogFile = existingLogFile;
+ return;
+ }
+
+ if (!File.Exists(file))
+ {
+ await NotificationProvider.ShowError($"Error loading log file '{Path.GetFileName(file)}'. The file could not be found.");
+ return;
+ }
+
List<LogItemBase> logs = new List<LogItemBase>();
LogFileTabViewVM logFile = new LogFileTabViewVM();
@@ -143,6 +178,15 @@ namespace Tango.FSE.LogViewer.UI.ViewModels
logFile.Logs = new ObservableCollection<LogItemBase>(logs);
LogFiles.Add(logFile);
SelectedLogFile = logFile;
+
+ Settings.RecentFiles.RemoveAll(x => x == logFile.File);
+ Settings.RecentFiles.Insert(0, logFile.File);
+ if (Settings.RecentFiles.Count > 10)
+ {
+ Settings.RecentFiles.Remove(Settings.RecentFiles.Last());
+ }
+ Settings.Save();
+ RecentLogFiles = Settings.RecentFiles.ToList();
}
}
catch (Exception ex)
@@ -231,6 +275,10 @@ namespace Tango.FSE.LogViewer.UI.ViewModels
private void OnApplicationReady(List<string> args)
{
+ Settings = SettingsManager.Default.GetOrCreate<LogViewerSettings>();
+ WrapLines = Settings.WrapLines;
+ RecentLogFiles = Settings.RecentFiles.ToList();
+
try
{
LogManager.Log("Starting file association IPC service...");
@@ -337,5 +385,30 @@ namespace Tango.FSE.LogViewer.UI.ViewModels
await NotificationProvider.ShowError($"Error loading the specified work item logs.\n{ex.FlattenMessage()}");
}
}
+
+ internal async void OnFilesDropped(List<string> files)
+ {
+ foreach (var file in files)
+ {
+ if (File.Exists(file))
+ {
+ if (Path.GetExtension(file).ToLower() == ".log")
+ {
+ await OpenLogFile(file);
+ }
+ }
+ }
+ }
+
+ private void OnWrapLinesChanged()
+ {
+ Settings.WrapLines = WrapLines;
+ Settings.Save();
+ }
+
+ private async void OpenRecentLogFile(string file)
+ {
+ await OpenLogFile(file);
+ }
}
}
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml
index 0f92a4abb..8ff1955bd 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml
+++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml
@@ -14,30 +14,50 @@
DataContext="{x:Static global:ViewModelLocator.LayoutViewVM}"
Background="{StaticResource FSE_PrimaryBackgroundBrush}"
Foreground="{StaticResource FSE_PrimaryForegroundBrush}">
- <Grid>
+
+ <UserControl.Resources>
+ <material:PackIcon x:Key="recentIcon" x:Shared="False" Kind="File" />
+ </UserControl.Resources>
+
+ <Grid AllowDrop="True" PreviewDrop="OnFileDrop">
<DockPanel>
<Grid DockPanel.Dock="Top">
- <!--MENU-->
- <Menu IsMainMenu="True">
- <MenuItem Header="_File">
- <MenuItem Header="_Open" Command="{Binding OpenLogFileCommand}" MinWidth="200" InputGestureText="CTRL+O">
- <MenuItem.Icon>
- <material:PackIcon Kind="File" />
- </MenuItem.Icon>
- </MenuItem>
- <MenuItem Header="_Save As" Command="{Binding SaveAsLogFileCommand}" MinWidth="200" InputGestureText="CTRL+Shit+S">
- <MenuItem.Icon>
- <material:PackIcon Kind="ContentSaveAll" />
- </MenuItem.Icon>
- </MenuItem>
- <Separator/>
- <MenuItem Header="_Quit" Command="{Binding ExitCommand}" MinWidth="200" InputGestureText="CTRL+Q">
- <MenuItem.Icon>
- <material:PackIcon Kind="CloseBox" />
- </MenuItem.Icon>
+ <!--MENU-->
+ <Menu IsMainMenu="True">
+ <MenuItem Header="_File">
+ <MenuItem Header="_Open" Command="{Binding OpenLogFileCommand}" MinWidth="200" InputGestureText="CTRL+O">
+ <MenuItem.Icon>
+ <material:PackIcon Kind="File" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <MenuItem Header="_Save As" Command="{Binding SaveAsLogFileCommand}" MinWidth="200" InputGestureText="CTRL+Shit+S">
+ <MenuItem.Icon>
+ <material:PackIcon Kind="ContentSaveAll" />
+ </MenuItem.Icon>
+ </MenuItem>
+ <Separator/>
+ <MenuItem ItemsSource="{Binding RecentLogFiles}" Header="Recent">
+ <MenuItem.Icon>
+ <material:PackIcon Kind="History" />
+ </MenuItem.Icon>
+ <MenuItem.ItemContainerStyle>
+ <Style TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}">
+ <Setter Property="FontSize" Value="{StaticResource FSE_SmallFontSize}"></Setter>
+ <Setter Property="Header" Value="{Binding}"></Setter>
+ <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.OpenRecentLogFileCommand}"></Setter>
+ <Setter Property="CommandParameter" Value="{Binding}"></Setter>
+ <Setter Property="Icon" Value="{StaticResource recentIcon}"></Setter>
+ </Style>
+ </MenuItem.ItemContainerStyle>
+ </MenuItem>
+ <Separator/>
+ <MenuItem Header="_Quit" Command="{Binding ExitCommand}" MinWidth="200" InputGestureText="CTRL+Q">
+ <MenuItem.Icon>
+ <material:PackIcon Kind="CloseBox" />
+ </MenuItem.Icon>
+ </MenuItem>
</MenuItem>
- </MenuItem>
- </Menu>
+ </Menu>
<Grid HorizontalAlignment="Right" Height="30" Margin="0 5 10 0">
<Grid.ToolTip>
@@ -143,7 +163,7 @@
<DockPanel>
<Border Padding="10" Height="51" DockPanel.Dock="Top" BorderBrush="{StaticResource FSE_BorderBrush}" BorderThickness="0 0 0 0.5">
- <CheckBox x:Name="chkWrap" IsChecked="True">WRAP LINES</CheckBox>
+ <CheckBox x:Name="chkWrap" IsChecked="{Binding WrapLines}">WRAP LINES</CheckBox>
</Border>
<TextBox BorderThickness="0" Padding="5" FontSize="{StaticResource FSE_SmallFontSize}" Foreground="{StaticResource FSE_GrayBrush}" Text="{Binding SelectedLogFile.SelectedLog.Message,Mode=OneWay}" IsReadOnly="True" AcceptsReturn="False" VerticalScrollBarVisibility="Auto" Background="{StaticResource FSE_PrimaryBackgroundDarkBrush}">
<TextBox.Style>
diff --git a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml.cs
index 4cb39fb95..d447947b3 100644
--- a/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml.cs
+++ b/Software/Visual_Studio/FSE/Tango.FSE.LogViewer.UI/Views/LayoutView.xaml.cs
@@ -12,6 +12,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
+using Tango.FSE.LogViewer.UI.ViewModels;
namespace Tango.FSE.LogViewer.UI.Views
{
@@ -20,9 +21,26 @@ namespace Tango.FSE.LogViewer.UI.Views
/// </summary>
public partial class LayoutView : UserControl
{
+ private LayoutViewVM _vm;
+
public LayoutView()
{
InitializeComponent();
+ Loaded += (_, __) => _vm = DataContext as LayoutViewVM;
+ }
+
+ private void OnFileDrop(object sender, DragEventArgs e)
+ {
+ try
+ {
+ string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
+
+ if (files != null)
+ {
+ _vm.OnFilesDropped(files.ToList());
+ }
+ }
+ catch { }
}
}
}