1212using System . Collections . Concurrent ;
1313using System . Text . RegularExpressions ;
1414using System . Runtime . InteropServices ;
15+ using System . Runtime . CompilerServices ;
1516
1617namespace Chizl . FileComparer
1718{
@@ -46,8 +47,11 @@ public partial class StartForm : Form
4647 private static RichTextBox _srcRtb ;
4748 private static RichTextBox _trgRtb ;
4849
49- private string _oldFile = ".\\ testfiles\\ test_old.txt" ;
50- private string _newFile = ".\\ testfiles\\ test_new.txt" ;
50+ //private string _oldFile = ".\\testfiles\\test_old.txt";
51+ //private string _newFile = ".\\testfiles\\test_new.txt";
52+ private string _oldFile = ".\\ testfiles\\ binary.old" ;
53+ private string _newFile = ".\\ testfiles\\ binary.new" ;
54+ //.\testfiles\binary.old
5155 //private string _oldFile = ".\\testfiles\\large_org.log";
5256 //private string _newFile = ".\\testfiles\\large_new.log";
5357
@@ -425,7 +429,7 @@ private void LoadBinaryHexView(string filePath, RichTextBox rtb)
425429
426430 private void SetStatus ( string msg , Color bgColor )
427431 {
428- StatusText . Text = $ "HexView auto zooms text based on window. Use Control-MouseWheel to Zoom In/Out. Click HexView again to exit HexView." ;
432+ StatusText . Text = msg ;
429433 if ( ! bgColor . IsEmpty )
430434 {
431435 // off
@@ -584,39 +588,38 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
584588 {
585589 ClearRichText ( ) ;
586590
591+ var scrollLineMarker = 0 ;
587592 var prevLineSize = 30 ;
588593 var useBinary = forceBinary || _lastFileComparison . IsBinary ;
589-
590594 if ( _lastFileComparison . HasException )
591595 {
592- SetStatus ( $ "Error: { _lastFileComparison . Exception . Message } ", Color . FromArgb ( 255 , 192 , 192 ) ) ;
596+ SetStatus ( $ "Exception: { _lastFileComparison . Exception . Message } ", Color . FromArgb ( 255 , 192 , 192 ) ) ;
593597 return ;
594598 }
595599 else
596600 {
597- SetStatus ( $ "Line by Line Status: Added( { _lastFileComparison . Diffs . Added } ), Deleted( { _lastFileComparison . Diffs . Deleted } ), Modified( { _lastFileComparison . Diffs . Modified } ), No Change({ _lastFileComparison . Diffs . Identical } )", Color . Yellow ) ;
601+ var groups = _lastFileComparison . IsBinary ? "Bytes" : "Lines" ;
602+ var statusType = _lastFileComparison . IsBinary ? "Binary by Byte" : $ "ASCII Line by Line{ ( forceBinary ? " in Hex" : "" ) } ";
603+ SetStatus ( $ "{ statusType } : Added( { _lastFileComparison . Diffs . Added } ), Deleted( { _lastFileComparison . Diffs . Deleted } ), Modified( { _lastFileComparison . Diffs . Modified } ), No Change( { _lastFileComparison . Diffs . Identical } ), Total { groups } ( { _lastFileComparison . LineComparison . Length } )", Color . FromArgb ( 192 , 192 , 0 ) ) ;
598604 }
599605
600- ResetTimer . Enabled = true ;
601- var lines = _lastFileComparison . LineComparison . OrderBy ( o => o . LineNumber ) . ToArray ( ) ;
602- // For Ascii, maxPerc isn't always 100% if form is zoomed. This is not taken in account and will stay the same.
603- var maxPerc = lines . Length ;
604- var scrollLineMarker = 0 ;
605- StatusText . Tag = $ "Lines: { lines . Length } / { lines . Count ( ) } ";
606-
607- var oldRtfBuilder = new RtfBuilder ( new Color [ 4 ] { LINE_COLOR , ADD_COLOR , DELETE_COLOR , MODIFIED_COLOR } ) ;
606+ var oldRtfBuilder = new RtfBuilder ( new Color [ 4 ] { LINE_COLOR , ADD_COLOR , DELETE_COLOR , MODIFIED_COLOR } , true ) ;
608607 var oldTextBuilder = new RtfBuilder ( new Color [ 4 ] { LINE_COLOR , ADD_COLOR , DELETE_COLOR , MODIFIED_COLOR } , false ) ;
609- var newRtfBuilder = new RtfBuilder ( new Color [ 4 ] { LINE_COLOR , ADD_COLOR , DELETE_COLOR , MODIFIED_COLOR } ) ;
608+ var newRtfBuilder = new RtfBuilder ( new Color [ 4 ] { LINE_COLOR , ADD_COLOR , DELETE_COLOR , MODIFIED_COLOR } , true ) ;
610609 var newTextBuilder = new RtfBuilder ( new Color [ 4 ] { LINE_COLOR , ADD_COLOR , DELETE_COLOR , MODIFIED_COLOR } , false ) ;
611610
611+ //ResetTimer.Enabled = true;
612+ var lines = _lastFileComparison . LineComparison . OrderBy ( o => o . LineNumber ) . ToArray ( ) ;
613+ var maxPerc = lines . Length ;
614+
612615 if ( ! useBinary )
613616 {
614617 var stringFiller = $ "{ new string ( ' ' , prevLineSize ) } \n ";
615618 foreach ( var cmpr in lines )
616619 {
617620 scrollLineMarker ++ ;
618-
619- var lineNumber = $ "{ cmpr . LineNumber : 0000 } : ";
621+ // using (000000000:) to match up with (X8h:) - 10 bytes wide.
622+ var lineNumber = $ "{ cmpr . LineNumber : 000000000 } : ";
620623 var lineString = $ "{ cmpr . LineDiffStr } ";
621624
622625 // removing any extra that might be residing..
@@ -634,11 +637,11 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
634637 lineString += "\n " ;
635638 }
636639
637- oldRtfBuilder . Append ( $ " { lineNumber } " , LINE_COLOR ) ;
640+ oldRtfBuilder . Append ( lineNumber , LINE_COLOR ) ;
638641 oldRtfBuilder . Append ( $ " ") ;
639642 if ( sideBySide )
640643 {
641- newRtfBuilder . Append ( $ " { lineNumber } " , LINE_COLOR ) ;
644+ newRtfBuilder . Append ( lineNumber , LINE_COLOR ) ;
642645 newRtfBuilder . Append ( $ " ") ;
643646 }
644647
@@ -726,14 +729,14 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
726729 {
727730 if ( hexSize . Equals ( 0 ) )
728731 {
729- var lineNumber = $ "{ hexCountLineMarker : X8} ";
732+ var lineNumber = $ "{ hexCountLineMarker : X8} h: \n ";
730733 hexCountLineMarker += 16 ;
731734
732- oldRtfBuilder . Append ( $ " { lineNumber } h " , LINE_COLOR ) ;
735+ oldRtfBuilder . Append ( lineNumber , LINE_COLOR ) ;
733736 oldRtfBuilder . Append ( " " ) ;
734737 if ( sideBySide )
735738 {
736- newRtfBuilder . Append ( $ " { lineNumber } h " , LINE_COLOR ) ;
739+ newRtfBuilder . Append ( lineNumber , LINE_COLOR ) ;
737740 newRtfBuilder . Append ( " " ) ;
738741 }
739742 }
@@ -816,8 +819,8 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
816819
817820 if ( hexSize >= 16 )
818821 {
819- oldRtfBuilder . Append ( " " ) ; //clears any color that might exist.
820- newRtfBuilder . Append ( " " ) ; //clears any color that might exist.
822+ oldRtfBuilder . Append ( " ; " ) ; //clears any color that might exist.
823+ newRtfBuilder . Append ( " ; " ) ; //clears any color that might exist.
821824 oldRtfBuilder . AppendLineRtf ( oldTextBuilder . GetDocument ( true ) ) ; //oldPlainText
822825 newRtfBuilder . AppendLineRtf ( newTextBuilder . GetDocument ( true ) ) ; //newPlainText
823826
@@ -836,8 +839,8 @@ private void ShowComparison(bool forceBinary = false, bool sideBySide = true)
836839 oldRtfBuilder . Append ( padString ) ;
837840 newRtfBuilder . Append ( padString ) ;
838841
839- oldRtfBuilder . Append ( " " ) ; //clears any color that might exist.
840- newRtfBuilder . Append ( " " ) ; //clears any color that might exist.
842+ oldRtfBuilder . Append ( " ; " ) ; //clears any color that might exist.
843+ newRtfBuilder . Append ( " ; " ) ; //clears any color that might exist.
841844 oldRtfBuilder . AppendLineRtf ( oldTextBuilder . GetDocument ( true ) ) ; //oldPlainText
842845 newRtfBuilder . AppendLineRtf ( newTextBuilder . GetDocument ( true ) ) ; //newPlainText
843846 }
@@ -939,5 +942,41 @@ private void ZoomCheck_KeyUp(object sender, KeyEventArgs e)
939942 _trgRtb . ZoomFactor = _srcRtb . ZoomFactor ;
940943 }
941944 private void Content_Leave ( object sender , EventArgs e ) => ZoomCheck_KeyUp ( sender , new KeyEventArgs ( Keys . ControlKey ) ) ;
945+
946+ private string _selectedText = string . Empty ;
947+ //private string _selectedTextRTF = string.Empty;
948+ private void Content_MouseUp ( object sender , MouseEventArgs e )
949+ {
950+ if ( e . Button == MouseButtons . Right )
951+ {
952+ var rtb = ( RichTextBox ) sender ;
953+ if ( rtb . SelectedText . Length > 0 )
954+ {
955+ _selectedText = rtb . SelectedText ;
956+ //_selectedTextRTF = rtb.SelectedRtf;
957+ RichTextContextMenus . Show ( GetMenuLocation ( rtb , e ) ) ;
958+ }
959+ }
960+ }
961+
962+ private Point GetMenuLocation ( RichTextBox rtb , MouseEventArgs e )
963+ {
964+ var titleHeight = SplitContainer1 . Top ;
965+ var curWidth = ( int ) Cursor . Size . Width / 4 ;
966+ var addLeft = SplitContainer1 . Margin . Left + curWidth ;
967+ var spltPanLeft = SplitContainer1 . Panel1 . Left + SplitContainer1 . Panel1 . Padding . Left + addLeft ;
968+
969+ if ( rtb . Name . StartsWith ( "New" ) )
970+ spltPanLeft = SplitContainer1 . Panel2 . Left + addLeft ;
971+
972+ var l = this . Left + spltPanLeft + rtb . Left ;
973+ var t = this . Top + rtb . Top + SplitContainer1 . Top ;
974+ return new Point ( l + e . X , t + e . Y + RichTextContextMenus . Height ) ;
975+ }
976+ private void RichTextBoxCopy_Click ( object sender , EventArgs e )
977+ {
978+ Clipboard . Clear ( ) ;
979+ Clipboard . SetText ( _selectedText ) ;
980+ }
942981 }
943982}
0 commit comments