Skip to content

Commit

Permalink
Fix crash bugs and tab positions
Browse files Browse the repository at this point in the history
  • Loading branch information
botman99 committed Jul 10, 2019
1 parent 18d575d commit 0ce3af3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Grepy2.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
; The name of the installer
Name "Grepy2"

!define VERSION '2.0.7'
!define VERSION '2.0.8'

; The file to write
OutFile "Grepy2-${VERSION}.exe"
Expand Down
6 changes: 5 additions & 1 deletion Grepy2Help/Grepy2.htm
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
</HEAD>
<BODY>
<p style="text-align:right">Previous&nbsp;&nbsp;&nbsp;<A href="WhatIsGrepy.htm">Next</a></p>
<p style="text-align:center">Grepy version 2.0.7</p>
<p style="text-align:center">Grepy version 2.0.8</p>
<br>
<br>
What's New:<br>
<br>
Version 2.0.8 - July 9, 2019<br>
<ul>
<li>Fix some crashing bugs and fix tab positions in RichTextBox.</li>
</ul>
Version 2.0.7 - June 16, 2018<br>
<ul>
<li>Fix dialogs so they center on the parent.</li>
Expand Down
32 changes: 26 additions & 6 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,24 @@ protected override void WndProc(ref Message m)
case Globals.WM_SLIDERUPDATE_NOTIFY_MAIN_THREAD:
{
// if there are more than 1,000 lines in the rich text box, then updating it will take some time, display a "Please Wait" dialog
if( RichTextBox.Lines.Length > 1000 )
if( TotalNumberOfSearchMatches > 1000 )
{
string msg = string.Format("{0} matches were found.\nThis could take a long time to display.\nAre you sure you wish to display all of the results?", TotalNumberOfSearchMatches);

if( TotalNumberOfSearchMatches > 5000 )
{
msg = string.Format("{0} matches were found.\nThis could take a REALLY long time (minutes) to display.\nAre you sure you wish to display all of the results?", TotalNumberOfSearchMatches);
}

DialogResult result = MessageBox.Show(msg, "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

if( result == DialogResult.No )
{
break;
}
}

if( TotalNumberOfSearchFileLines > 1000 )
{
PleaseWaitDeferredIndex = ListViewFileClickedOnIndex;
PleaseWaitForceDisplay = false;
Expand Down Expand Up @@ -687,7 +704,7 @@ private void DeferReDisplayRichTextSearchMatches(int IndexToDisplay)

if( TotalNumberOfSearchMatches > 5000 )
{
msg = string.Format("{0} matches were found.\nThis could take a REALLY, REALLY long time (minutes) to display.\nAre you sure you wish to display all of the results?", TotalNumberOfSearchMatches);
msg = string.Format("{0} matches were found.\nThis could take a REALLY long time (minutes) to display.\nAre you sure you wish to display all of the results?", TotalNumberOfSearchMatches);
}

DialogResult result = MessageBox.Show(msg, "WARNING", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
Expand Down Expand Up @@ -774,7 +791,10 @@ private void ReDisplayRichTextSearchMatches(int IndexToDisplay, bool bForceDispl
}
}

MatchSyncLineOffset = TopLineIndex - RichTextMatchSyncList[MatchSyncLineIndex];
if (MatchSyncLineIndex >= 0)
{
MatchSyncLineOffset = TopLineIndex - RichTextMatchSyncList[MatchSyncLineIndex];
}

bSyncronizeUsingMatchLine = true;
}
Expand Down Expand Up @@ -1088,8 +1108,6 @@ private void MainForm_Load(object sender, EventArgs e)

ColumnWidthSize = new int[6];

int[] TabPositions = new int[32]; // RichTextBox only supports 32 tab positions

// create a right-click menu in the FileListView to perform various functions ("copy files to clipboard", etc.)
MenuItem[] flv_mi = new MenuItem[] { new MenuItem("Copy Filenames To Clipboard"), new MenuItem("Export to CSV File") };

Expand All @@ -1106,12 +1124,14 @@ private void MainForm_Load(object sender, EventArgs e)
Size sz = TextRenderer.MeasureText(graphics, "W", RichTextBox.Font, font_sz, TextFormatFlags.NoPadding);
graphics.Dispose();

int[] TabPositions = new int[32]; // RichTextBox only supports 32 tab positions

// set the RichText tab positions (assumes tab size of 4 characters)
int tab_size = 4 * sz.Width;

for(int x = 0; x < 32; x++)
{
TabPositions[x] = (x+1) * tab_size;
TabPositions[x] = (sz.Width * 10) + ((x+1) * tab_size); // we prepend "{0,8}: " (10 characters) for the line number at the beginning of lines, offset by this many characters for first tab stop
}

RichTextBox.SelectionTabs = TabPositions;
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.7.0")]
[assembly: AssemblyFileVersion("2.0.7.0")]
[assembly: AssemblyVersion("2.0.8.0")]
[assembly: AssemblyFileVersion("2.0.8.0")]
57 changes: 36 additions & 21 deletions Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,41 +402,56 @@ private void AddMatchLine(ref string line, ref List<MatchPos> Matches, ref strin
if( LinesSinceMatch >= 0 )
{
LinesSinceMatch++;
if( (LinesSinceMatch == 5) || (sr.Peek() == -1) ) // if we're read 5 lines or reached the end of the file...
{
int PreviewIndex = PreviewLineIndex - (PreviewLineCount - 1); // index in the circular buffer of the oldest preview line
if( PreviewIndex < 0 )
{
PreviewIndex += 5;
}

for( int index = 0; index < PreviewLineCount; index++ )
try
{
if( (LinesSinceMatch == 5) || (sr.Peek() == -1) ) // if we're read 5 lines or reached the end of the file...
{
Globals.SearchLine PreviewSearchLine = new Globals.SearchLine();

PreviewSearchLine.LineNumber = LineNumber - (PreviewLineCount - index) + 1;
PreviewSearchLine.Line = PreviewLines[PreviewIndex++];
if( PreviewIndex == 5 )
int PreviewIndex = PreviewLineIndex - (PreviewLineCount - 1); // index in the circular buffer of the oldest preview line
if( PreviewIndex < 0 )
{
PreviewIndex = 0;
PreviewIndex += 5;
}
PreviewSearchLine.bIsSearchTextMatch = false;

Globals.SearchFiles[SearchFilesIndex].Lines.Add(PreviewSearchLine);
}
for( int index = 0; index < PreviewLineCount; index++ )
{
Globals.SearchLine PreviewSearchLine = new Globals.SearchLine();

PreviewSearchLine.LineNumber = LineNumber - (PreviewLineCount - index) + 1;
PreviewSearchLine.Line = PreviewLines[PreviewIndex++];
if( PreviewIndex == 5 )
{
PreviewIndex = 0;
}
PreviewSearchLine.bIsSearchTextMatch = false;

Globals.SearchFiles[SearchFilesIndex].Lines.Add(PreviewSearchLine);
}

PreviewLineIndex = -1; // reset the circular buffer
PreviewLineCount = 0;
PreviewLineIndex = -1; // reset the circular buffer
PreviewLineCount = 0;

LinesSinceMatch = -1;
LinesSinceMatch = -1;
}
}
catch( Exception e )
{
Console.WriteLine("ScanFileForMatches() Exception: {0}", e.Message);
}
}
}

NumberOfMatchesInFile += MatchesInLine;
}

sr.Close();
try
{
sr.Close();
}
catch( Exception e )
{
Console.WriteLine("ScanFileForMatches() Exception: {0}", e.Message);
}

if (Globals.bShouldStopWorkerJobs)
{
Expand Down

0 comments on commit 0ce3af3

Please sign in to comment.