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

Daniel Burrows dburrows at costa.debian.org
Wed Aug 10 00:36:28 UTC 2005


Author: dburrows
Date: Wed Aug 10 00:36:25 2005
New Revision: 3796

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/defaults.cc
   branches/aptitude-0.3/aptitude/src/solution_screen.cc
Log:
Let the user interactively narrow the search for a solution.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Aug 10 00:36:25 2005
@@ -1,5 +1,10 @@
 2005-08-09  Daniel Burrows  <dburrows at debian.org>
 
+	* src/defaults.cc, src/solution_fragment.cc:
+
+	  Use the new methods to allow the user to interactively narrow
+	  the search for a solution.
+
 	* src/generic/aptcache.cc, src/generic/aptcache.h:
 
 	  Add hooks in the apt cache interface layer for manipulating

Modified: branches/aptitude-0.3/aptitude/src/defaults.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/defaults.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/defaults.cc	Wed Aug 10 00:36:25 2005
@@ -71,6 +71,9 @@
   global_bindings.set("ApplySolution", key(L'!', false));
   global_bindings.set("DumpResolver", key(L'*', false));
 
+  global_bindings.set("SolutionActionReject", key(L'r', false));
+  global_bindings.set("SolutionActionAccept", key(L'a', false));
+
   pkg_tree::init_bindings();
   pkg_tree_node::init_bindings();
   cmine::init_bindings();
@@ -93,6 +96,9 @@
 
   set_style("Bullet", style_fg(COLOR_YELLOW)+style_attrs_on(A_BOLD));
   set_style("TrustWarning", style_fg(COLOR_RED)+style_bg(COLOR_BLACK)+style_attrs_on(A_BOLD));
+
+  set_style("SolutionActionRejected", style_fg(COLOR_WHITE)+style_bg(COLOR_RED));
+  set_style("SolutionActionAccepted", style_fg(COLOR_WHITE)+style_bg(COLOR_GREEN));
 }
 
 void init_defaults()

Modified: branches/aptitude-0.3/aptitude/src/solution_screen.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/solution_screen.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/solution_screen.cc	Wed Aug 10 00:36:25 2005
@@ -170,6 +170,90 @@
     return L"";
   }
 
+  bool is_forbidden()
+  {
+    assert((*apt_cache_file)->resolver_exists());
+
+    return (*apt_cache_file)->resolver_is_forbidden(ver);
+  }
+
+  // Dual of forbidding.
+  bool is_mandatory()
+  {
+    assert((*apt_cache_file)->resolver_exists());
+
+    aptitude_universe::package p = ver.get_package();
+
+    for(aptitude_universe::package::version_iterator vi = p.versions_begin();
+	!vi.end(); ++vi)
+      {
+	aptitude_universe::version v2 = *vi;
+
+	if(v2 == ver)
+	  {
+	    if((*apt_cache_file)->resolver_is_forbidden(v2))
+	      return false;
+	  }
+	else
+	  {
+	    if(!(*apt_cache_file)->resolver_is_forbidden(v2))
+	      return false;
+	  }
+      }
+
+    return true;
+  }
+
+  void forbid()
+  {
+    (*apt_cache_file)->resolver_forbid_version(ver);
+  }
+
+  void unforbid()
+  {
+    (*apt_cache_file)->resolver_unforbid_version(ver);
+  }
+
+  void mandate()
+  {
+    aptitude_universe::package p = ver.get_package();
+
+    for(aptitude_universe::package::version_iterator vi = p.versions_begin();
+	!vi.end(); ++vi)
+      {
+	aptitude_universe::version v2 = *vi;
+
+	if(v2 == ver)
+	  (*apt_cache_file)->resolver_unforbid_version(v2);
+	else
+	  (*apt_cache_file)->resolver_forbid_version(v2);
+      }
+  }
+
+  void unmandate()
+  {
+    aptitude_universe::package p = ver.get_package();
+
+    for(aptitude_universe::package::version_iterator vi = p.versions_begin();
+	!vi.end(); ++vi)
+      {
+	aptitude_universe::version v2 = *vi;
+
+	if(v2 != ver)
+	  (*apt_cache_file)->resolver_unforbid_version(v2);
+      }
+  }
+
+  style get_normal_style()
+  {
+    if(is_forbidden())
+      return get_style("SolutionActionRejected");
+    else if(is_mandatory())
+      return get_style("SolutionActionAccepted");
+    else
+      return style();
+  }
+
   void paint(vs_tree *win, int y, bool hierarchical, const style &st)
   {
     unsigned int basex = hierarchical ? 2*get_depth() : 0;
@@ -178,6 +262,24 @@
     unsigned int x = 0;
 
     win->move(y, 0);
+
+    if(x < width)
+      {
+	if(is_forbidden())
+	  win->addch('R'); // For "reject"
+	else if(is_mandatory())
+	  win->addch('A'); // For "accept"
+	else
+	  win->addch(' ');
+	++x;
+      }
+
+    if(x < width)
+      {
+	win->addch(' ');
+	++x;
+      }
+
     while(x < width && x < basex)
       {
 	win->addch(' ');
@@ -264,6 +366,28 @@
 	++x;
       }
   }
+
+  bool dispatch_key(const key &k, vs_tree *owner)
+  {
+    if(global_bindings.key_matches(k, "SolutionActionReject"))
+      {
+	if(is_forbidden())
+	  unforbid();
+	else
+	  forbid();
+      }
+    else if(global_bindings.key_matches(k, "SolutionActionAccept"))
+      {
+	if(is_mandatory())
+	  unmandate();
+	else
+	  mandate();
+      }
+    else
+      return vs_treeitem::dispatch_key(k, owner);
+
+    return true;
+  }
 };
 
 vs_subtree_generic *make_solution_tree(const aptitude_solution &sol)



More information about the Aptitude-svn-commit mailing list