Skip to content

Commit

Permalink
Merge pull request #25 from MarkusPalcer/HandleMultiSelection
Browse files Browse the repository at this point in the history
Handle multi selection
  • Loading branch information
MarkusPalcer authored May 24, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents ff541a6 + 7e0f6fc commit 70aacc6
Showing 7 changed files with 76 additions and 18 deletions.
1 change: 1 addition & 0 deletions AndroidLogViewer/AndroidLogViewer.csproj
Original file line number Diff line number Diff line change
@@ -58,6 +58,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Command\BindingRedirector.cs" />
<Compile Include="Command\PropertyObserver.cs" />
<Compile Include="Command\PropertyObserverNode.cs" />
<Compile Include="Dialogs\Base\DialogViewModelBase.cs" />
36 changes: 36 additions & 0 deletions AndroidLogViewer/Command/BindingRedirector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Windows;

namespace AndroidLogViewer.Command
{
public class BindingRedirector : DependencyObject
{
public static readonly DependencyProperty LeftProperty = DependencyProperty.Register(
"Left", typeof(object), typeof(BindingRedirector), new PropertyMetadata(default(object), LeftChanged));

private static void LeftChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((BindingRedirector) d).Right = e.NewValue;
}

public object Left
{
get { return (object) GetValue(LeftProperty); }
set { SetValue(LeftProperty, value); }
}

public static readonly DependencyProperty RightProperty = DependencyProperty.Register(
"Right", typeof(object), typeof(BindingRedirector), new PropertyMetadata(default(object) , RightChanged));

private static void RightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((BindingRedirector) d).Left = e.NewValue;
}

public object Right
{
get { return (object) GetValue(RightProperty); }
set { SetValue(RightProperty, value); }
}

}
}
7 changes: 6 additions & 1 deletion AndroidLogViewer/Dialogs/Export/ExportDialogViewModel.cs
Original file line number Diff line number Diff line change
@@ -97,13 +97,18 @@ private void ExecuteConfirmCommand()
}
else
{
lines = _entries.Select(x=> $"{x.Time} {x.Process} {x.Thread} {x.Level} {x.Tag}: {x.Message}");
lines = _entries.Select(FormatLogEntry);
}


File.WriteAllLines(FileName, lines);

Done(null);
}

public static string FormatLogEntry(LogEntry x)
{
return $"{x.Time} {x.Process} {x.Thread} {x.Level} {x.Tag}: {x.Message}";
}
}
}
18 changes: 14 additions & 4 deletions AndroidLogViewer/LogcatParser.cs
Original file line number Diff line number Diff line change
@@ -14,12 +14,13 @@ public class LogcatParser
private const string TagRegularExpression = "(?<tag>[^:]+):";
private const string MessageRegularExpression = "(?<message>.*)";
private static readonly string TrailingLineRegularExpression =$"(?<trailingline>\\s+?){MessageRegularExpression}";
private static readonly string DefaultLogcatRegularExpression = $"(?<premessage>{DateTimeRegularExpression}\\s+{PidRegularExpression}\\s+{TidRegularExpression}\\s+{LogLevelRegularExpression}\\s+{TagRegularExpression}\\s+?){MessageRegularExpression}";
private static readonly string AndroidStudioRegularExpression = $"(?<premessage>{DateTimeRegularExpression}\\s+{PidRegularExpression}-{TidRegularExpression}[^\\s]+\\s+{LogLevelRegularExpression}/{TagRegularExpression}\\s+?){MessageRegularExpression}";
private static readonly string DefaultLogcatRegularExpression = $"(?<premessage>{DateTimeRegularExpression}\\s+{PidRegularExpression}\\s+{TidRegularExpression}\\s+{LogLevelRegularExpression}\\s*{TagRegularExpression}\\s+?){MessageRegularExpression}";
private static readonly string AndroidStudioRegularExpression = $"(?<premessage>{DateTimeRegularExpression}\\s+{PidRegularExpression}-{TidRegularExpression}[^\\s]+\\s*{LogLevelRegularExpression}/{TagRegularExpression}\\s+?){MessageRegularExpression}";
private static readonly string StartOfLogExpression = "(?<startoflog>\\s*---+)(?<message>.*)";


private static readonly string[] RecognizedRegularExpressions = {DefaultLogcatRegularExpression, AndroidStudioRegularExpression, TrailingLineRegularExpression};
private static readonly string Pattern = $"^{string.Join("|", RecognizedRegularExpressions.Select(x => $"({x})"))}$";
private static readonly string[] RecognizedRegularExpressions = {DefaultLogcatRegularExpression, AndroidStudioRegularExpression, TrailingLineRegularExpression, StartOfLogExpression};
private static readonly string Pattern = $"{string.Join("|", RecognizedRegularExpressions.Select(x => $"^({x})$"))}";
private static readonly Regex RegularExpression = new Regex(Pattern, RegexOptions.Compiled);

static LogcatParser()
@@ -41,6 +42,7 @@ public static ObservableCollection<LogEntry> ReadLogEntries(TextReader reader)
if (match.Success)
{
LogEntry newEntry = null;

if (match.Groups["datetime"].Success)
{
newEntry = new LogEntry
@@ -56,6 +58,13 @@ public static ObservableCollection<LogEntry> ReadLogEntries(TextReader reader)

pivotEntry = newEntry;
}
else if (match.Groups["startoflog"].Success)
{
newEntry = new LogEntry
{
Message = $"--- {match.Groups["message"].Value.Trim()}"
};
}
else if (match.Groups["trailingline"].Success && pivotEntry != null)
{
var trimmedMessage = match.Groups["message"].Value.Trim();
@@ -72,6 +81,7 @@ public static ObservableCollection<LogEntry> ReadLogEntries(TextReader reader)
Time = pivotEntry.Time,
};
}

if (newEntry != null) result.Add(newEntry);
}

7 changes: 7 additions & 0 deletions AndroidLogViewer/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -212,6 +212,9 @@
Style="{StaticResource MonospaceFont}"
SelectedIndex="{Binding SelectedLogEntryIndex}"
SelectedItem="{Binding Path=SelectedLogEntry, Mode=OneWayToSource}">
<ListView.CommandBindings>
<CommandBinding Command="Copy" Executed="ExecuteCopyLogItems"/>
</ListView.CommandBindings>
<ListView.Resources>
<ContextMenu x:Key="ItemContextMenu">
<MenuItem
@@ -286,6 +289,10 @@
<MenuItem
Command="{Binding Path=DataContext.RemoveTrailingLinesCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}"
Header="Delete all lines after this" />

<MenuItem Header="Export selected items"
CommandParameter="{Binding Path=SelectedItems, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}"
Command="{Binding Path=DataContext.ExportSelectionCommand, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}" />
</ContextMenu>
</ListView.Resources>
<ListView.View>
19 changes: 6 additions & 13 deletions AndroidLogViewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AndroidLogViewer
{
@@ -31,5 +19,10 @@ private void CloseWindow(object sender, RoutedEventArgs e)
{
Close();
}

private void ExecuteCopyLogItems(object sender, ExecutedRoutedEventArgs e)
{
(DataContext as MainWindowViewModel)?.CopySelectionCommand?.Execute(LogItems.SelectedItems);
}
}
}
6 changes: 6 additions & 0 deletions AndroidLogViewer/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@ public MainWindowViewModel()
ExportCommand = new DelegateCommand(
() => ShowDialog<ExportDialogViewModel, object>(new ExportDialogViewModel(_defaultView.OfType<LogEntry>().ToArray())).FireAndForget(),
() => !string.IsNullOrEmpty(FileName)).ObservesProperty(() => FileName);
ExportSelectionCommand = new DelegateCommand<IEnumerable<object>>(x => ShowDialog<ExportDialogViewModel, object>(new ExportDialogViewModel(x.OfType<LogEntry>().ToArray())).FireAndForget());
CopySelectionCommand = new DelegateCommand<IEnumerable<object>>(items => Clipboard.SetText(string.Join("\n", items.OfType<LogEntry>().Select(ExportDialogViewModel.FormatLogEntry))));

OpenFileCommand = new DelegateCommand(OpenFile);
OpenUrlCommand = new DelegateCommand(OpenUrl);
@@ -149,6 +151,10 @@ private bool FilterLogEntries(object x)

public ICommand ExportCommand { get; }

public ICommand ExportSelectionCommand { get; }

public ICommand CopySelectionCommand { get; }

#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;

0 comments on commit 70aacc6

Please sign in to comment.