2323using System . Net . NetworkInformation ;
2424using System . Runtime . CompilerServices ;
2525using System . Runtime . InteropServices . WindowsRuntime ;
26+ using System . Text . RegularExpressions ;
2627using System . Threading . Tasks ;
2728using Windows . ApplicationModel ;
2829using Windows . ApplicationModel . Activation ;
@@ -559,8 +560,8 @@ private async void FileDrop(DragEventArgs e)
559560
560561 private async void FileItemTapped ( object sender , TappedRoutedEventArgs e )
561562 {
562- var treeviewitem = ( sender as MyTreeViewItem ) ;
563- var fileitem = treeviewitem . DataContext as FileItem ;
563+ MyTreeViewItem treeviewitem = sender as MyTreeViewItem ;
564+ FileItem fileitem = treeviewitem . DataContext as FileItem ;
564565
565566 if ( fileitem . Type == FileItem . ExplorerItemType . File )
566567 {
@@ -577,6 +578,7 @@ private async void FileItemTapped(object sender, TappedRoutedEventArgs e)
577578 tip . HeroContent = content ;
578579 tip . HeroContentPlacement = TeachingTipHeroContentPlacementMode . Bottom ;
579580 RootGrid . Children . Add ( tip ) ;
581+
580582 tip . IsOpen = true ;
581583 }
582584 else if ( type == ".pdf" )
@@ -691,8 +693,15 @@ public async void CompileTex(bool compileRoot = false, FileItem fileToCompile =
691693 App . VM . IsError = true ;
692694 StorageFile errorfile = error as StorageFile ;
693695 string text = await FileIO . ReadTextAsync ( errorfile ) ;
694- string newtext = text . Replace ( " " , "" ) . Replace ( "return" , "" ) . Replace ( "[\" " , "\" " ) . Replace ( "\" ]" , "\" " ) . Replace ( @"\n" , "" ) . Replace ( "=" , ":" ) ;
696+
697+ // BAD code, quick hack to convert the lua table to a json format. Depending on special characters in the error message, the JsonConvert.DeserializeObject function can through errors.
698+ string newtext = text . Replace ( " " , "" ) . Replace ( "return" , "" ) . Replace ( "[\" " , "\" " ) . Replace ( "\" ]" , "\" " ) . Replace ( "=" , ":" ) ;
699+ string pattern = @"([^\\])(\\n)" ; // Matches every \n except \\n
700+ string replacement = "$1" ; // Match gets replaced with first capturing group, e.g. ]\n --> ]
701+ newtext = Regex . Replace ( newtext , pattern , replacement ) ;
702+
695703 var errormessage = JsonConvert . DeserializeObject < ConTeXtErrorMessage > ( newtext ) ;
704+
696705 App . VM . Log ( "Compiler error: " + errormessage . lasttexerror ) ;
697706 App . VM . ConTeXtErrorMessage = errormessage ;
698707 }
@@ -884,13 +893,22 @@ private async void Tabs_TabCloseRequested(TabView sender, TabViewTabCloseRequest
884893 VM . CurrentProject . LastOpenedFiles = VM . FileItems . Select ( x => x . FileName ) . ToList ( ) ;
885894 }
886895
887- private void Pin_Click ( object sender , RoutedEventArgs e )
896+ private async void Pin_Click ( object sender , RoutedEventArgs e )
888897 {
889898 var fi = ( FileItem ) ( sender as FrameworkElement ) . DataContext ;
899+
900+ if ( ! fi . IsPinned ) {
901+ bool reselect = fi == VM . CurrentFileItem ;
902+ VM . FileItems . Remove ( fi ) ;
903+ VM . FileItems . Insert ( 0 , fi ) ;
904+ if ( reselect )
905+ {
906+ await Task . Delay ( 500 ) ;
907+ VM . CurrentFileItem = fi ;
908+ }
909+ }
910+
890911 fi . IsPinned = ! fi . IsPinned ;
891- int currind = VM . FileItems . IndexOf ( fi ) ;
892- if ( currind > 0 )
893- VM . FileItems . Move ( currind , 0 ) ;
894912 }
895913
896914 #endregion
0 commit comments