Index: app/widgets/gimppaletteeditor.c
===================================================================
RCS file: /cvs/gnome/gimp/app/widgets/gimppaletteeditor.c,v
retrieving revision 1.189
diff -u -p -r1.189 gimppaletteeditor.c
--- app/widgets/gimppaletteeditor.c	19 Dec 2005 22:37:49 -0000	1.189
+++ app/widgets/gimppaletteeditor.c	26 Feb 2006 14:47:05 -0000
@@ -808,3 +808,121 @@ palette_editor_scroll_top_left (GimpPale
   if (vadj)
     gtk_adjustment_set_value (vadj, 0.0);
 }
+
+
+void
+gimp_palette_editor_next_color (GimpPaletteEditor *editor)
+{
+  GList *tmp;
+  GimpPalette *palette;
+
+  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+  
+  tmp = g_list_find(palette->colors, editor->color);
+
+  if (tmp == NULL)
+    return;
+
+  g_return_if_fail(editor->view != NULL);
+ 
+  if (tmp->next)
+    gimp_palette_view_select_entry( GIMP_PALETTE_VIEW(editor->view),
+                                   (GimpPaletteEntry *)(tmp->next->data));  
+}
+
+
+void
+gimp_palette_editor_previous_color (GimpPaletteEditor *editor)
+{
+  GList       *tmp;
+  GimpPalette *palette;
+
+  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+  tmp = g_list_find(palette->colors, editor->color);
+  
+  g_return_if_fail(editor->view != NULL);
+  
+  if (tmp->prev)
+    gimp_palette_view_select_entry( GIMP_PALETTE_VIEW(editor->view),
+                                   (GimpPaletteEntry *)(tmp->prev->data));
+
+}
+
+void 
+gimp_palette_editor_go( GimpPaletteEditor *editor,
+                        gint               absolute,
+                        gint               amount)
+{
+  GimpPalette *palette;
+  GList       *list;
+  gint         index;
+
+  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+  g_return_if_fail(palette != NULL);
+
+
+  if (absolute)
+    index = amount;
+  else
+    { 
+      index = g_list_index(palette->colors, editor->color);
+      if (index == -1)
+	index = 0;
+      index += amount;
+    }
+
+  /* for some reason CLAMP doesn't work here -- it wraps -1 to 255 (palette len == 256)
+   */
+  if (index < 0)
+    index = 0;
+  else 
+    {
+      gint maxi = g_list_length(palette->colors) - 1;
+      if (index >= maxi)
+        index = maxi;
+    }
+
+  list = g_list_nth(palette->colors, index);
+
+  if (list)
+      gimp_palette_view_select_entry( GIMP_PALETTE_VIEW(editor->view),
+                                   (GimpPaletteEntry *)(list->data));
+}
+
+void
+gimp_palette_editor_current_color( GimpPaletteEditor *editor,
+                                   GimpRGB           *color)
+{
+  GimpRGB *tmp;
+  g_return_if_fail(editor != NULL);
+  if (editor->color == NULL)
+    return;
+  tmp = &(editor->color->color);
+  color->r = tmp->r;
+  color->g = tmp->g;
+  color->b = tmp->b;
+}
+
+gint
+gimp_palette_editor_color_index(GimpPaletteEditor *editor,
+				GimpRGB           *color)
+{
+  GimpPalette *palette;
+  gint         i;
+  GimpRGB     *palcolor;
+  GList       *list;
+  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+  list = palette->colors;
+  i = 0;
+  while (list)
+    {
+      palcolor = &( ( (GimpPaletteEntry *)(list->data))->color );
+      if (palcolor->r == color->r && palcolor->g == color->g && palcolor->b == color->b)
+	return i;
+
+      list = list->next;
+      i++;
+    }
+
+  return -1;
+}
Index: app/widgets/gimppaletteeditor.h
===================================================================
RCS file: /cvs/gnome/gimp/app/widgets/gimppaletteeditor.h,v
retrieving revision 1.36
diff -u -p -r1.36 gimppaletteeditor.h
--- app/widgets/gimppaletteeditor.h	14 Jul 2005 18:37:33 -0000	1.36
+++ app/widgets/gimppaletteeditor.h	26 Feb 2006 14:47:05 -0000
@@ -70,5 +70,16 @@ void        gimp_palette_editor_pick_col
 void        gimp_palette_editor_zoom       (GimpPaletteEditor  *editor,
                                             GimpZoomType        zoom_type);
 
+void        gimp_palette_editor_next_color        (GimpPaletteEditor  *editor);
+void        gimp_palette_editor_previous_color    (GimpPaletteEditor  *editor);
+void        gimp_palette_editor_go                (GimpPaletteEditor *editor,
+                                                   gint               absolute,
+                                                   gint               amount);
+
+gint        gimp_palette_editor_color_index       (GimpPaletteEditor  *editor, 
+                                                   GimpRGB *color);
+
+void        gimp_palette_editor_current_color     (GimpPaletteEditor  *editor,
+                                                   GimpRGB *color);
 
 #endif /* __GIMP_PALETTE_EDITOR_H__ */
Index: app/widgets/gimpcolormapeditor.c
===================================================================
RCS file: /cvs/gnome/gimp/app/widgets/gimpcolormapeditor.c,v
retrieving revision 1.88
diff -u -p -r1.88 gimpcolormapeditor.c
--- app/widgets/gimpcolormapeditor.c	29 Dec 2005 00:11:09 -0000	1.88
+++ app/widgets/gimpcolormapeditor.c	26 Feb 2006 14:47:07 -0000
@@ -787,3 +787,85 @@ gimp_colormap_image_colormap_changed (Gi
   if (ncol == editor->col_index || ncol == -1)
     gimp_colormap_editor_update_entries (editor);
 }
+
+
+
+void
+gimp_colormap_editor_next_color(GimpColormapEditor *editor)
+{
+  gint newval;
+  g_return_if_fail(editor != NULL);
+  g_return_if_fail( HAVE_COLORMAP( GIMP_IMAGE_EDITOR (editor)->gimage));
+
+  newval = MIN (editor->col_index + 1, editor->index_adjustment->upper);
+  gimp_colormap_editor_set_index (editor, newval);  
+
+}
+
+void
+gimp_colormap_editor_previous_color(GimpColormapEditor *editor)
+{
+  gint newval;
+  g_return_if_fail(editor != NULL);
+  g_return_if_fail( HAVE_COLORMAP( GIMP_IMAGE_EDITOR (editor)->gimage));
+
+  newval = MAX (editor->col_index - 1, 0);
+  gimp_colormap_editor_set_index (editor, newval);  
+
+}
+
+void
+gimp_colormap_editor_go(GimpColormapEditor *editor,
+			gint                absolute,
+			gint                amount)
+{
+  gint newval;
+  g_return_if_fail(editor != NULL);
+  g_return_if_fail( HAVE_COLORMAP( GIMP_IMAGE_EDITOR (editor)->gimage));
+
+  newval = editor->col_index + amount;
+  if (absolute)
+    newval = amount;
+  newval = CLAMP (newval, 0, editor->index_adjustment->upper);
+  gimp_colormap_editor_set_index (editor, newval);  
+
+}
+
+
+void
+gimp_colormap_editor_current_color(GimpColormapEditor *editor,
+				   GimpRGB            *color)
+{
+  g_return_if_fail(editor != NULL);
+  g_return_if_fail( HAVE_COLORMAP(GIMP_IMAGE_EDITOR (editor)->gimage));
+  
+  {
+    guchar    *colormap = GIMP_IMAGE_EDITOR (editor)->gimage->cmap;
+    gint       i        = editor->col_index;
+
+    gimp_rgb_set_uchar(color, colormap[i * 3], colormap[i * 3 + 1], colormap[i * 3 + 2]);
+  }
+}
+
+
+gint
+gimp_colormap_editor_color_index(GimpColormapEditor *editor,
+				 GimpRGB            *color)
+{
+  guchar    *colormap;
+  guchar     r,g,b;
+  gint       i;
+
+  g_return_val_if_fail( HAVE_COLORMAP(GIMP_IMAGE_EDITOR (editor)->gimage), -1);
+
+  colormap = GIMP_IMAGE_EDITOR (editor)->gimage->cmap;
+  gimp_rgb_get_uchar(color, &r,&g,&b);
+
+  for (i = 0; i <= editor->index_adjustment->upper; i++)
+    {
+      if (colormap[i * 3] == r && colormap[i * 3 + 1] == g && colormap[i * 3 + 2] == b)
+	return i;
+    }
+  return -1;
+
+}
Index: app/widgets/gimpcolormapeditor.h
===================================================================
RCS file: /cvs/gnome/gimp/app/widgets/gimpcolormapeditor.h,v
retrieving revision 1.20
diff -u -p -r1.20 gimpcolormapeditor.h
--- app/widgets/gimpcolormapeditor.h	19 Jul 2005 19:37:07 -0000	1.20
+++ app/widgets/gimpcolormapeditor.h	26 Feb 2006 14:47:07 -0000
@@ -71,5 +71,17 @@ void        gimp_colormap_editor_selecte
                                             GdkModifierType     state);
 gint        gimp_colormap_editor_col_index (GimpColormapEditor *editor);
 
+void        gimp_colormap_editor_next_color    (GimpColormapEditor *editor);
+void        gimp_colormap_editor_previous_color(GimpColormapEditor *editor);
+void        gimp_colormap_editor_go            (GimpColormapEditor *editor,
+						gint absolute,
+						gint amount);
+
+void        gimp_colormap_editor_current_color(GimpColormapEditor *editor,
+					       GimpRGB *color);
+
+gint        gimp_colormap_editor_color_index  (GimpColormapEditor *editor,
+					       GimpRGB *color);
+
 
 #endif /* __GIMP_COLORMAP_EDITOR_H__ */
Index: app/actions/context-commands.c
===================================================================
RCS file: /cvs/gnome/gimp/app/actions/context-commands.c,v
retrieving revision 1.10
diff -u -p -r1.10 context-commands.c
--- app/actions/context-commands.c	27 Apr 2005 12:23:01 -0000	1.10
+++ app/actions/context-commands.c	26 Feb 2006 14:47:08 -0000
@@ -33,10 +33,10 @@
 #include "core/gimpdatafactory.h"
 #include "core/gimplist.h"
 
+
 #include "actions.h"
 #include "context-commands.h"
 
-
 static const GimpLayerModeEffects paint_modes[] =
 {
   GIMP_NORMAL_MODE,
@@ -71,6 +71,8 @@ static void   context_select_object    (
                                         GimpContainer        *container);
 static gint   context_paint_mode_index (GimpLayerModeEffects  paint_mode);
 
+static GimpPaletteEditor   *context_get_palette_editor();
+
 
 /*  public functions  */
 
@@ -608,3 +610,100 @@ context_paint_mode_index (GimpLayerModeE
 
   return i;
 }
+
+
+/* XXX make this into a separate compile */
+ 
+#include "context-commands-palette.ch"
+
+#define MAXENTRY 16777216
+
+/* preprocessor simplifications for things I couldn't factor out */
+
+#define MATCH() context_match_color(&color)
+
+#define INITFG()	    \
+  GimpRGB            color; \
+  GimpContext       *context; \
+ \
+  return_if_no_context(context, data); \
+  gimp_context_get_foreground(context, &color)
+
+#define ENDFG() gimp_context_set_foreground(context, &color)
+#define INITBG()	    \
+  GimpRGB            color; \
+  GimpContext       *context; \
+ \
+  return_if_no_context(context, data); \
+  gimp_context_get_background(context, &color)
+
+#define ENDBG() gimp_context_set_background(context, &color)
+
+void
+context_foreground_next_in_pal_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+  INITFG();
+  MATCH();  
+  context_get_next_in_palette(&color);
+  ENDFG();
+
+}
+
+void
+context_foreground_next_in_pal_skip_cmd_callback( GtkAction *action,
+                                                  gpointer   data)
+{
+  INITFG();
+  MATCH();  
+  context_skip_in_palette(SKIPSTEP, &color);
+  ENDFG();
+
+}
+
+void
+context_foreground_first_in_pal_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+
+  GimpRGB            color;
+  GimpContext       *context;
+
+  return_if_no_context(context, data);
+  context_color_from_palette_index(0, &color);
+  ENDFG();
+
+}
+
+void
+context_foreground_last_in_pal_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+  INITFG();
+  context_color_from_palette_index(MAXENTRY, &color);
+  ENDFG();
+}
+
+
+void
+context_foreground_previous_in_pal_cmd_callback( GtkAction *action,
+                                                 gpointer   data)
+{
+  INITFG();
+  MATCH();
+  context_get_previous_in_palette(&color);
+  ENDFG();
+}
+
+
+void
+context_foreground_previous_in_pal_skip_cmd_callback( GtkAction *action,
+                                                      gpointer   data)
+{
+  INITFG();
+  MATCH();
+  context_skip_in_palette(-SKIPSTEP, &color);
+  ENDFG();
+}
+
+/* background changers go here */
Index: app/actions/context-commands.h
===================================================================
RCS file: /cvs/gnome/gimp/app/actions/context-commands.h,v
retrieving revision 1.9
diff -u -p -r1.9 context-commands.h
--- app/actions/context-commands.h	27 Apr 2005 12:23:01 -0000	1.9
+++ app/actions/context-commands.h	26 Feb 2006 14:47:08 -0000
@@ -110,5 +110,24 @@ void   context_brush_angle_cmd_callback 
                                              gint       value,
                                              gpointer   data);
 
+void   context_foreground_next_in_pal_cmd_callback  (GtkAction   *action,
+                                                     gpointer     data);
+
+void   context_foreground_next_in_pal_skip_cmd_callback  (GtkAction   *action,
+							  gpointer     data);
+
+
+void   context_foreground_previous_in_pal_cmd_callback  (GtkAction   *action,
+                                                         gpointer     data);
+
+void   context_foreground_previous_in_pal_skip_cmd_callback  (GtkAction   *action,
+                                                         gpointer     data);
+
+void   context_foreground_first_in_pal_cmd_callback     (GtkAction   *action,
+                                                         gpointer     data);
+
+void   context_foreground_last_in_pal_cmd_callback      (GtkAction   *action,
+                                                         gpointer     data);
+
 
 #endif /* __CONTEXT_COMMANDS_H__ */
Index: app/actions/context-actions.c
===================================================================
RCS file: /cvs/gnome/gimp/app/actions/context-actions.c,v
retrieving revision 1.18
diff -u -p -r1.18 context-actions.c
--- app/actions/context-actions.c	21 Nov 2005 16:08:13 -0000	1.18
+++ app/actions/context-actions.c	26 Feb 2006 14:47:09 -0000
@@ -69,7 +69,44 @@ static GimpActionEntry context_actions[]
   { "context-colors-swap", GIMP_STOCK_SWAP_COLORS,
     N_("S_wap Colors"), "X", NULL,
     G_CALLBACK (context_colors_swap_cmd_callback),
-    GIMP_HELP_TOOLBOX_SWAP_COLORS }
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  /* XXX give this its own group */
+
+
+  { "context-foreground-next-in-palette", GIMP_STOCK_SWAP_COLORS,
+    N_("Set Foreground from next palette color"), NULL, NULL,
+    G_CALLBACK (context_foreground_next_in_pal_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  { "context-foreground-prev-in-palette", GIMP_STOCK_SWAP_COLORS,
+    N_("Set Foreground from previous palette color"), NULL, NULL,
+    G_CALLBACK (context_foreground_previous_in_pal_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  { "context-foreground-next-in-palette-skip", GIMP_STOCK_SWAP_COLORS,
+    N_("Set Foreground from (current + N) palette color"), NULL, NULL,
+    G_CALLBACK (context_foreground_next_in_pal_skip_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  { "context-foreground-prev-in-palette-skip", GIMP_STOCK_SWAP_COLORS,
+    N_("Set Foreground from (current - N) palette color"), NULL, NULL,
+    G_CALLBACK (context_foreground_previous_in_pal_skip_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  /* XXX ambiguity */
+
+  { "context-foreground-first-in-palette", GIMP_STOCK_SWAP_COLORS,
+    N_("Set Foreground from minimum palette color"), NULL, NULL,
+    G_CALLBACK (context_foreground_first_in_pal_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  { "context-foreground-last-in-palette", GIMP_STOCK_SWAP_COLORS,
+    N_("Set Foreground from maximum palette color"), NULL, NULL,
+    G_CALLBACK (context_foreground_last_in_pal_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+
 };
 
 static GimpEnumActionEntry context_foreground_red_actions[] =
Index: app/core/gimppalette.c
===================================================================
RCS file: /cvs/gnome/gimp/app/core/gimppalette.c,v
retrieving revision 1.63
diff -u -p -r1.63 gimppalette.c
--- app/core/gimppalette.c	10 Dec 2005 19:24:35 -0000	1.63
+++ app/core/gimppalette.c	26 Feb 2006 14:47:11 -0000
@@ -654,6 +654,28 @@ gimp_palette_delete_entry (GimpPalette  
     }
 }
 
+gint
+gimp_palette_color_index (GimpPalette *palette,
+                          GimpRGB     *color)
+{
+  GList   *list;
+  GimpRGB *data;
+  gint     i;
+  g_return_val_if_fail (GIMP_IS_PALETTE (palette),-1);
+  list = palette->colors;
+  g_return_val_if_fail( list != NULL, -1);
+  i = 0;
+  while (list)
+    {
+      data = (GimpRGB *)&( ( (GimpPaletteEntry *)(list->data))->color);
+      if (data->r == color->r && data->g == color->g && data->b == color->b)
+	return i;
+      list = list->next;
+      i++;
+    }
+  return -1;
+}
+
 void
 gimp_palette_set_columns (GimpPalette *palette,
                           gint         columns)
Index: app/core/gimppalette.h
===================================================================
RCS file: /cvs/gnome/gimp/app/core/gimppalette.h,v
retrieving revision 1.26
diff -u -p -r1.26 gimppalette.h
--- app/core/gimppalette.h	1 Sep 2005 18:06:21 -0000	1.26
+++ app/core/gimppalette.h	26 Feb 2006 14:47:11 -0000
@@ -76,6 +76,10 @@ GimpPaletteEntry * gimp_palette_add_entr
 void               gimp_palette_delete_entry (GimpPalette      *palette,
                                               GimpPaletteEntry *entry);
 
+gint               gimp_palette_color_index  (GimpPalette      *palette,
+                                              GimpRGB          *color);
+
+
 void               gimp_palette_set_columns  (GimpPalette      *palette,
                                               gint              columns);
 gint               gimp_palette_get_columns  (GimpPalette      *palette);
