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	25 Feb 2006 09:38:07 -0000
@@ -808,3 +808,85 @@ 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;
+    }
+  index = CLAMP(index, 0, g_list_length(palette->colors));
+  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_get_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;
+}
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	25 Feb 2006 09:38:07 -0000
@@ -70,5 +70,18 @@ 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);
+
+/* XXX is needed? */
+
+gint        gimp_palette_editor_find_color        (GimpPaletteEditor  *editor, 
+                                                   GimpRGB *color);
+
+void        gimp_palette_editor_get_current_color (GimpPaletteEditor  *editor,
+                                                   GimpRGB *color);
 
 #endif /* __GIMP_PALETTE_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	25 Feb 2006 09:38:08 -0000
@@ -33,10 +33,17 @@
 #include "core/gimpdatafactory.h"
 #include "core/gimplist.h"
 
+#include "widgets/gimppaletteeditor.h"
+#include "widgets/gimpdialogfactory.h"
+#include "widgets/gimppaletteeditor.h"
+#include "widgets/gimpsessioninfo.h"
+
+
 #include "actions.h"
 #include "context-commands.h"
 
 
+
 static const GimpLayerModeEffects paint_modes[] =
 {
   GIMP_NORMAL_MODE,
@@ -71,6 +78,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  */
 
@@ -607,4 +616,94 @@ context_paint_mode_index (GimpLayerModeE
     i++;
 
   return i;
+}
+
+
+GimpPaletteEditor *context_get_palette_editor()
+{
+  GimpDialogFactory *dialog_factory;
+  GimpSessionInfo   *info;
+  GtkWidget         *palette_editor = NULL;
+  dialog_factory = gimp_dialog_factory_from_name ("dock");
+  g_return_val_if_fail(dialog_factory != NULL, NULL);
+  info = gimp_dialog_factory_find_session_info (dialog_factory,
+                                                "gimp-palette-editor");
+  g_return_val_if_fail(info != NULL, NULL);
+  if (info && info->widget)
+    palette_editor = gtk_bin_get_child (GTK_BIN (info->widget));
+
+  g_return_val_if_fail(palette_editor != NULL, NULL);
+  return GIMP_PALETTE_EDITOR(palette_editor);
+
+}
+
+void
+context_foreground_next_in_pal_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+  GimpPaletteEditor *editor;
+  GimpRGB            color;
+  GimpContext       *context;
+
+  return_if_no_context(context, data);
+  editor = context_get_palette_editor();
+  g_return_if_fail(editor != NULL);
+  gimp_palette_editor_next_color( editor); 
+  gimp_palette_editor_get_current_color( editor, &color);
+  gimp_context_set_foreground(context, &color);
+
+}
+
+void
+context_foreground_previous_in_pal_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+  GimpPaletteEditor *editor;
+  GimpRGB            color;
+  GimpContext       *context;
+
+  return_if_no_context(context, data);
+  editor = context_get_palette_editor();
+  g_return_if_fail(editor != NULL);
+  gimp_palette_editor_previous_color( editor); 
+  gimp_palette_editor_get_current_color( editor, &color);
+  gimp_context_set_foreground(context, &color);
+
+}
+
+/* XXX change this */
+#define SKIPSTEP 4
+
+void
+context_foreground_next_in_pal_skip_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+  GimpPaletteEditor *editor;
+  GimpRGB            color;
+  GimpContext       *context;
+
+  return_if_no_context(context, data);
+  editor = context_get_palette_editor();
+  g_return_if_fail(editor != NULL);
+  gimp_palette_editor_go( editor, TRUE, SKIPSTEP); 
+  gimp_palette_editor_get_current_color( editor, &color);
+  gimp_context_set_foreground(context, &color);
+
+}
+
+void
+context_foreground_previous_in_pal_skip_cmd_callback( GtkAction *action,
+                                             gpointer   data)
+{
+  GimpPaletteEditor *editor;
+  GimpRGB            color;
+  GimpContext       *context;
+
+  return_if_no_context(context, data);
+  editor = context_get_palette_editor();
+  g_return_if_fail(editor != NULL);
+  gimp_palette_editor_go( editor, FALSE, -SKIPSTEP); 
+  gimp_palette_editor_get_current_color( editor, &color);
+  gimp_context_set_foreground(context, &color);
+
 }
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	25 Feb 2006 09:38:08 -0000
@@ -110,5 +110,12 @@ 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_previous_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	25 Feb 2006 09:38:10 -0000
@@ -69,7 +69,18 @@ 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 },
+
+  { "context-colors-next-fg-from-palette", GIMP_STOCK_SWAP_COLORS,
+    N_("Ne_xt FGcolor from palette"), NULL, NULL,
+    G_CALLBACK (context_foreground_next_in_pal_cmd_callback),
+    GIMP_HELP_TOOLBOX_SWAP_COLORS },
+
+  { "context-colors-prev-fg-from-palette", GIMP_STOCK_SWAP_COLORS,
+    N_("Pre_vious FGcolor from palette"), NULL, NULL,
+    G_CALLBACK (context_foreground_previous_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	25 Feb 2006 09:38:12 -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	25 Feb 2006 09:38:12 -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);
