@@ -68,9 +68,12 @@ public MainWindow()
6868
6969 SettingsWindow . Load ( ) ;
7070
71- if ( SettingsWindow . IsFirstRun ( ) && ! SettingsWindow . ShowSettingsDialog ( ) == true )
71+ if ( SettingsWindow . IsFirstRun ( ) )
7272 {
73- Application . Current . Shutdown ( ) ;
73+ if ( SettingsWindow . ShowSettingsDialog ( ) == true )
74+ ApplySettings ( ) ;
75+ else
76+ Application . Current . Shutdown ( ) ;
7477 }
7578
7679 notificationIcon = SaveNotifyLogoFromResource ( ) ;
@@ -254,8 +257,8 @@ private void OpenLogFile(string fullPath)
254257 logWatcher . ReadToEndLine ( ) ;
255258 LogsGrid . ItemsSource = logLines ;
256259 Filter . Text = filterValue ;
257- gridScrollViewer = GetScrollViewer ( LogsGrid ) ;
258- gridScrollViewer . ScrollToEnd ( ) ;
260+ LogsGrid . ScrollIntoView ( logLines . Last ( ) ) ;
261+
259262 logWatcher . StartWatch ( gridUpdatePeriod ) ;
260263
261264 var tenants = logLines . Where ( l => ! string . IsNullOrEmpty ( l . Tenant ) ) . Select ( l => l . Tenant ) . Distinct ( ) . OrderBy ( l => l ) ;
@@ -302,29 +305,9 @@ private void Files_SelectionChanged(object sender, SelectionChangedEventArgs e)
302305 dialog . Filters . Add ( new CommonFileDialogFilter ( "Log Files (*.log)" , ".log" ) ) ;
303306
304307 if ( CommonFileDialogResult . Ok == dialog . ShowDialog ( ) )
305- {
306- var logFiles = comboBox . Items . Cast < LogFile > ( ) . ToList ( ) ;
307-
308- var logFile = logFiles . FirstOrDefault ( l => string . Equals ( l . FullPath , dialog . FileName , StringComparison . InvariantCultureIgnoreCase ) ) ;
309-
310- if ( logFile != null )
311- {
312- comboBox . SelectedItem = logFile ;
313- }
314- else
315- {
316- // Создать фоновый обработчик для нового файла.
317- LogHandlers . Add ( new LogHandler ( dialog . FileName , notificationIcon ) ) ;
318-
319- logFile = new LogFile ( dialog . FileName ) ;
320- comboBox . Items . Insert ( comboBox . Items . Count - 1 , logFile ) ;
321- comboBox . SelectedItem = logFile ;
322- }
323- }
308+ SelectFileToOpen ( dialog . FileName ) ;
324309 else
325- {
326310 comboBox . SelectedItem = null ;
327- }
328311
329312 return ;
330313 }
@@ -335,23 +318,6 @@ private void Files_SelectionChanged(object sender, SelectionChangedEventArgs e)
335318 OpenLogFile ( openedFileFullPath ) ;
336319 }
337320
338- private ScrollViewer GetScrollViewer ( UIElement element )
339- {
340- if ( element == null )
341- return null ;
342-
343- ScrollViewer result = null ;
344- for ( int i = 0 ; i < VisualTreeHelper . GetChildrenCount ( element ) && result == null ; i ++ )
345- {
346- if ( VisualTreeHelper . GetChild ( element , i ) is ScrollViewer )
347- result = ( ScrollViewer ) ( VisualTreeHelper . GetChild ( element , i ) ) ;
348- else
349- result = GetScrollViewer ( VisualTreeHelper . GetChild ( element , i ) as UIElement ) ;
350- }
351-
352- return result ;
353- }
354-
355321 private void OnBlockNewLines ( List < string > lines , bool isEndFile , double progress )
356322 {
357323 var convertedLogLines = Converter . ConvertLinesToObjects ( lines ) ;
@@ -413,19 +379,19 @@ private void LogsGrid_SelectionChanged(object sender, SelectionChangedEventArgs
413379 DetailText . Text = String . Empty ;
414380
415381 if ( ! String . IsNullOrEmpty ( line . UserName ) )
416- DetailText . Text += $ "UserName: { line . UserName } \n ";
382+ DetailText . Text += $ "UserName: { line . UserName } \n ";
417383
418384 if ( ! String . IsNullOrEmpty ( line . Tenant ) )
419- DetailText . Text += $ "Tenant: { line . Tenant } \n ";
385+ DetailText . Text += $ "Tenant: { line . Tenant } \n ";
420386
421387 if ( ! String . IsNullOrEmpty ( line . Pid ) )
422- DetailText . Text += $ "Pid: { line . Pid } \n ";
388+ DetailText . Text += $ "Pid: { line . Pid } \n ";
423389
424390 if ( ! String . IsNullOrEmpty ( line . Trace ) )
425- DetailText . Text += $ "Trace: { line . Trace } \n ";
391+ DetailText . Text += $ "Trace: { line . Trace } \n ";
426392
427393 if ( ! String . IsNullOrEmpty ( line . Version ) )
428- DetailText . Text += $ "Version: { line . Version } \n ";
394+ DetailText . Text += $ "Version: { line . Version } \n ";
429395
430396 if ( ! String . IsNullOrEmpty ( line . FullMessage ) )
431397 {
@@ -446,6 +412,7 @@ private void Settins_Click(object sender, RoutedEventArgs e)
446412 {
447413 if ( SettingsWindow . ShowSettingsDialog ( ) == true )
448414 {
415+ ApplySettings ( ) ;
449416 // TODO сделать применение настроек без перезапуска приложения.
450417 MessageBox . Show ( "Settings will be applied after restarting the application" ) ;
451418 Application . Current . Shutdown ( ) ;
@@ -618,5 +585,46 @@ private void ColumnVisibilityUnchecked(object sender, RoutedEventArgs e)
618585 columns . Visibility = Visibility . Collapsed ;
619586 }
620587 }
588+
589+ private void ApplySettings ( )
590+ {
591+ if ( SettingsWindow . AssociateLogFile == true )
592+ FileAssociations . SetAssociation ( ) ;
593+ else
594+ FileAssociations . RemoveAssociation ( ) ;
595+ }
596+
597+ private void SelectFileToOpen ( string fileName )
598+ {
599+ var logFiles = LogsFileNames . Items . Cast < LogFile > ( ) . ToList ( ) ;
600+
601+ var logFile = logFiles . FirstOrDefault ( l => string . Equals ( l . FullPath , fileName , StringComparison . InvariantCultureIgnoreCase ) ) ;
602+
603+ if ( logFile != null )
604+ {
605+ LogsFileNames . SelectedItem = logFile ;
606+ }
607+ else
608+ {
609+ // Создать фоновый обработчик для нового файла.
610+ LogHandlers . Add ( new LogHandler ( fileName , notificationIcon ) ) ;
611+
612+ logFile = new LogFile ( fileName ) ;
613+ LogsFileNames . Items . Insert ( LogsFileNames . Items . Count - 1 , logFile ) ;
614+ LogsFileNames . SelectedItem = logFile ;
615+ }
616+ }
617+
618+ private void Window_ContentRendered ( object sender , EventArgs e )
619+ {
620+ var args = Environment . GetCommandLineArgs ( ) ;
621+ if ( args . Length > 1 )
622+ {
623+ var fileName = args [ 1 ] ;
624+
625+ if ( File . Exists ( fileName ) && Path . GetExtension ( fileName ) == ".log" )
626+ SelectFileToOpen ( fileName ) ;
627+ }
628+ }
621629 }
622630}
0 commit comments