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

Daniel Burrows dburrows at costa.debian.org
Wed Aug 17 16:01:19 UTC 2005


Author: dburrows
Date: Wed Aug 17 16:01:16 2005
New Revision: 3886

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc
Log:
Clean up and adjust some of the vs_tree routines.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Aug 17 16:01:16 2005
@@ -1,3 +1,12 @@
+2005-08-17  Daniel Burrows  <dburrows at debian.org>
+
+	* src/vscreen/vs_tree.cc:
+
+	  Clean up line_up and line_down (NB: it's not quite clear that
+	  their behavior is identical) and rewrite set_selection so that
+	  it adjusts the top of the screen correctly, at the cost of a
+	  line_of call.
+
 2005-08-16  Daniel Burrows  <dburrows at debian.org>
 
 	* src/vscreen/vs_tree.cc:

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_tree.cc	Wed Aug 17 16:01:16 2005
@@ -231,11 +231,50 @@
     }
   else
     {
-      if(selected!=end)
-	selected->unhighlighted(this);
-      selected=top=to;
-      if(selected!=end)
-	selected->highlighted(this);
+      int height = getmaxy();
+      if(height == 0)
+	{
+	  selected = top = to;
+	  return;
+	}
+
+      // Give up and just directly determine the line of 'to'.
+      int l = line_of(to);
+
+      while(l < 1)
+	{
+	  assert(top != end);
+
+	  if(hierarchical)
+	    --top;
+	  else
+	    top.move_backward_level();
+
+	  ++l;
+	}
+
+      while(l > height)
+	{
+	  assert(top != end);
+
+	  if(hierarchical)
+	    ++top;
+	  else
+	    top.move_forward_level();
+
+	  --l;
+	}
+
+      if(selected != to)
+	{
+	  if(selected != end)
+	    selected->unhighlighted(this);
+
+	  if(to != end)
+	    to->highlighted(this);
+	}
+
+      selected = to;
 
       vscreen_update();
     }
@@ -262,69 +301,54 @@
   if(!hierarchical)
     --height;
 
-  if(selected!=end)
-    {
-      vs_treeiterator orig=selected,prevtop=top;
-      selected->unhighlighted(this);
+  vs_treeiterator orig = selected, prevtop = top;
 
-      int newline=line_of(selected);
-      bool movedonce=false;
+  int newline = line_of(selected);
+  int scrollcount = 0;
+  bool moved = false;
+
+  while(selected != end &&
+	scrollcount < 1 &&
+	(!moved || !selected->get_selectable()))
+    {
+      if(hierarchical)
+	++selected;
+      else
+	selected.move_forward_level();
 
-      while(newline<height &&
-	    selected!=end &&
-	    (!movedonce || !selected->get_selectable()))
-	{
-	  ++selected;
-	  ++newline;
-	  movedonce=true;
-	}
+      ++newline;
+      moved = true;
 
-      if(newline==height &&
-	 selected!=end &&
-	 (!movedonce || !selected->get_selectable()))
-	// We ran off the screen and couldn't find anything to select,
-	// or we started at the bottom of the screen.
+      if(newline > height)
 	{
-	  ++selected;
-
-	  if(selected!=end)
-	    {
-	      // Shift the top forward.
-	      ++top;
+	  if(hierarchical)
+	    ++top;
+	  else
+	    top.move_forward_level();
 
-	      if(!selected->get_selectable())
-		// Ok, well, we still can't select this.  Too bad.
-		{
-		  selected=orig;
-
-		  if(selected==prevtop)
-		    // We moved forward by one, so the previous top
-		    // needs to be moved forward.  (saves an
-		    // expensive line_of call)
-		    {
-		      selected=top;
-		      int l=0;
-
-		      while(selected!=end &&
-			    !selected->get_selectable() &&
-			    l<height)
-			{
-			  ++selected;
-			  ++l;
-			}
-		    }
-		}
-	    }
+	  --newline;
+	  ++scrollcount;
 	}
+    }
 
-      if(selected==end)
+  if(selected == end)
+    {
+      if(hierarchical)
 	--selected;
+      else
+	selected.move_backward_level();
+    }
 
-      if(selected!=end)
-	selected->highlighted(this);
+  if(orig != selected)
+    {
+      if(orig != end)
+	orig->unhighlighted(this);
 
-      vscreen_update();
+      if(selected != end)
+	selected->highlighted(this);
     }
+
+  vscreen_update();
 }
 
 void vs_tree::set_hierarchical(bool _hierarchical)
@@ -367,64 +391,29 @@
     --height;
 
   vs_treeiterator orig=selected;
-  if(selected!=end)
-    selected->unhighlighted(this);
 
-  if(selected!=begin)
-    {
-      bool movedonce=false;
+  bool moved = false;
+  int scrollcount = 0;
 
-      while(selected!=begin &&
-	    selected!=top &&
-	    (!movedonce || !selected->get_selectable()))
-	{
-	  if(hierarchical)
-	    --selected;
-	  else
-	    selected.move_backward_level();
-	  movedonce=true;
-	}
-
-      if(selected==top &&
-	 selected!=begin &&
-	 (!movedonce || !selected->get_selectable()))
-	// We ran off the screen and couldn't find anything to select,
-	// or we started at the top of the screen.
+  while(selected != begin &&
+	scrollcount < 1 &&
+	(!moved || !selected->get_selectable()))
+    {
+      if(selected == top)
 	{
 	  if(hierarchical)
-	    --selected;
-	  else
-	    selected.move_backward_level();
-
-	  // The top always moves.  If it is the beginning, something
-	  // is seriously messed up.
-	  assert(top!=begin);
-	  if(hierarchical)
 	    --top;
 	  else
 	    top.move_backward_level();
-	  if(!selected->get_selectable())
-	    // Oops.  Even moving one more doesn't give us anything
-	    // to select.  Restore the selection.
-	    {
-	      selected=orig;
-	      if(line_of(selected)>height)
-		// If the selection was pushed off the screen,
-		// bring it back on.
-		{
-		  if(hierarchical)
-		    --selected;
-		  else
-		    selected.move_backward_level();
-
-		  while(selected!=top && !selected->get_selectable())
-		    if(hierarchical)
-		      --selected;
-		    else
-		      selected.move_backward_level();
-		}
-	    }
+
+	  ++scrollcount;
 	}
+
+      if(hierarchical)
+	--selected;
+      else
+	selected.move_backward_level();
+      moved = true;
     }
 
   // Handle the special case where the first element of the tree is
@@ -438,8 +427,14 @@
 	selected = begin;
     }
 
-  if(selected!=end)
-    selected->highlighted(this);
+  if(orig != selected)
+    {
+      if(orig != end)
+	orig->unhighlighted(this);
+
+      if(selected != end)
+	selected->highlighted(this);
+    }
 
   vscreen_update();
 }



More information about the Aptitude-svn-commit mailing list