From 280145e984283daa11fe81329246ad23b77cd8f3 Mon Sep 17 00:00:00 2001
From: Mike Buland <eichlan@xagasoft.com>
Date: Wed, 23 Jun 2010 23:39:12 +0000
Subject: find works.

---
 src/tools/viewcsv.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 3 deletions(-)

(limited to 'src')

diff --git a/src/tools/viewcsv.cpp b/src/tools/viewcsv.cpp
index 649ec9e..176f25e 100644
--- a/src/tools/viewcsv.cpp
+++ b/src/tools/viewcsv.cpp
@@ -284,10 +284,76 @@ public:
 		}
 	}
 
+	void resetCaret()
+	{
+		sysCaret.reset();
+	}
+
+	void findNext( const Bu::FString &sTerm )
+	{
+		int y = sysCaret.iRow;
+		if( y < 0 )
+			y = 0;
+		int x = sysCaret.iCol+1;
+		for( ; y < doc.sgData.getSize(); y++ )
+		{
+			StrArray &aRow = doc.sgData[y];
+			for( ; x < aRow.getSize(); x++ )
+			{
+				if( aRow[x].find( sTerm ) )
+				{
+					sysCaret.iRow = y;
+					sysCaret.iCol = x;
+					scrollToCaret();
+					return;
+				}
+			}
+			x = 0;
+		}
+	}
+
+	void scrollToCaret()
+	{
+		iXOff = sysCaret.iCol;
+		iYOff = sysCaret.iRow;
+	}
+
 	CsvDoc &doc;
 	int iXOff;
 	int iYOff;
 	bool bHeaderRow;
+
+	class Caret
+	{
+	public:
+		Caret() :
+			iRow( -1 ),
+			iCol( -1 )
+		{
+		}
+
+		virtual ~Caret()
+		{
+		}
+
+
+		void reset()
+		{
+			iRow = iCol = -1;
+		}
+
+		bool isSet()
+		{
+			if( iRow < 0 || iCol < 0 )
+				return false;
+			return true;
+		}
+
+		int iRow;
+		int iCol;
+	};
+
+	Caret sysCaret;
 };
 
 int main( int argc, char *argv[] )
@@ -327,6 +393,8 @@ int main( int argc, char *argv[] )
 	CsvView view( doc );
 	view.setHeaderRow( opt.bHeader );
 
+	Bu::FString sSearchTerm;
+
 	bool bRun = true;
 	do
 	{
@@ -372,9 +440,13 @@ int main( int argc, char *argv[] )
 				break;
 
 			case '/':
-				{
-					Bu::FString sIn = view.prompt("find: ");
-				}
+				sSearchTerm = view.prompt("find: ");
+				view.resetCaret();
+				view.findNext( sSearchTerm );
+				break;
+
+			case 'n':
+				view.findNext( sSearchTerm );
 				break;
 
 			case 'h':
-- 
cgit v1.2.3