[Aptitude-svn-commit] r4200 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows at costa.debian.org
Fri Sep 23 02:04:20 UTC 2005


Author: dburrows
Date: Fri Sep 23 02:04:17 2005
New Revision: 4200

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h
Log:
Add pager support for searching backwards.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Sep 23 02:04:17 2005
@@ -1,5 +1,9 @@
 2005-09-22  Daniel Burrows  <dburrows at debian.org>
 
+	* src/vscreen/vs_pager.cc, src/vscreen/vs_pager.h:
+
+	  Add support for searching backwards in a file.
+
 	* src/menu_redirect.cc, src/menu_redirect.h, src/pkg_node.cc, src/solution_item.cc:
 
 	  Write default implementations for the menu_redirect methods that

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.cc	Fri Sep 23 02:04:17 2005
@@ -203,7 +203,7 @@
     scroll_down(getmaxy());
 }
 
-void vs_pager::search_for(const wstring &s)
+void vs_pager::search_omnidirectional_for(const wstring &s, bool forward)
 {
   vs_widget_ref tmpref(this);
 
@@ -215,11 +215,12 @@
       return;
     }
 
-  line_count i=first_line+1;
+  line_count i = forward ? first_line + 1 : first_line - 1;
 
-  for( ; i<lines.size(); ++i)
+  while(i > 0 && i < lines.size())
     {
-      wstring::size_type loc=lines[i].find(last_search);
+      wstring::size_type loc
+	= forward ? lines[i].find(last_search) : lines[i].rfind(last_search);
 
       if(loc!=wstring::npos)
 	{
@@ -250,6 +251,11 @@
 	  vscreen_update();
 	  return;
 	}
+
+      if(forward)
+	++i;
+      else
+	--i;
     }
   beep();
 }

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_pager.h	Fri Sep 23 02:04:17 2005
@@ -40,6 +40,9 @@
   /** Handles resizing the widget. */
   void layout_me();
 
+  /** The workhorse search routine. */
+  void search_omnidirectional_for(const std::wstring &s, bool forward);
+
 protected:
   vs_pager(const char *text, int len, const char *encoding = NULL);
   vs_pager(const std::string &s, const char *encoding = NULL);
@@ -142,7 +145,19 @@
    *
    *  \param s the string to search for
    */
-  void search_for(const std::wstring &s);
+  void search_for(const std::wstring &s)
+  {
+    search_omnidirectional_for(s, true);
+  }
+
+  /** Find the previous line containing the given string.
+   *
+   *  \param s the string to search for
+   */
+  void search_back_for(const std::wstring &s)
+  {
+    search_omnidirectional_for(s, false);
+  }
 
   /** Return the last string which the user searched for. */
   std::wstring get_last_search() {return last_search;}



More information about the Aptitude-svn-commit mailing list