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	28 Feb 2006 09:06:19 -0000
@@ -808,3 +808,90 @@ palette_editor_scroll_top_left (GimpPale
   if (vadj)
     gtk_adjustment_set_value (vadj, 0.0);
 }
+
+
+gboolean gimp_palette_editor_go ( GimpPaletteEditor *editor,
+                                  gint               offset,
+                                  GimpRGB           *color)
+{
+  GimpPalette *palette;
+  GList       *list   = NULL;
+  GimpRGB     *palcolor;
+  gboolean     need_search;
+
+  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+  list = palette->colors;
+  
+  need_search = TRUE;
+  if (editor->color != NULL)
+    {
+      palcolor = &(editor->color->color);
+      if (palcolor->r == color->r && palcolor->g == color->g && palcolor->b == color->b)
+        {
+          list = g_list_find( palette->colors, editor->color);
+          need_search = FALSE;
+        }
+    }
+
+  if (need_search)
+    {
+      while (list)
+        {
+          palcolor = &( ( (GimpPaletteEntry *)(list->data))->color );
+          if (palcolor->r == color->r && palcolor->g == color->g && palcolor->b == color->b)
+            break;
+          
+          list = list->next;
+        }
+    }
+  
+  if (list == NULL)
+    {
+      /* default to 0th entry */
+      palcolor = &((GimpPaletteEntry *)(palette->colors->data))->color;
+      color->r = palcolor->r;
+      color->g = palcolor->g;
+      color->b = palcolor->b;
+      gimp_palette_view_select_entry( GIMP_PALETTE_VIEW(editor->view),
+                                      (GimpPaletteEntry *)(palette->colors->data));
+      return TRUE;
+    }
+
+  /* move */
+  if (offset > 0)
+    {
+      while (offset && list->next)
+        {
+          list = list->next;
+          offset--;
+        }
+      palcolor = &( ((GimpPaletteEntry *)(list->data))->color);
+      gimp_palette_view_select_entry( GIMP_PALETTE_VIEW(editor->view),
+                                      (GimpPaletteEntry *)(list->data));
+    }
+  else if (offset < 0)
+    {
+      while (offset && list->prev)
+        {
+          list = list->prev;
+          offset++;
+        }
+      palcolor = &( ((GimpPaletteEntry *)(list->data))->color);
+      gimp_palette_view_select_entry( GIMP_PALETTE_VIEW(editor->view),
+                                      (GimpPaletteEntry *)(list->data));
+    }
+
+  color->r = palcolor->r;
+  color->g = palcolor->g;
+  color->b = palcolor->b;
+  return TRUE;
+}
+
+gint
+gimp_palette_editor_get_num_entries(GimpPaletteEditor *editor)
+{
+  GimpPalette *palette;
+
+  palette = GIMP_PALETTE (GIMP_DATA_EDITOR (editor)->data);
+  return g_list_length(palette->colors);
+}
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	28 Feb 2006 09:06:19 -0000
@@ -70,5 +70,10 @@ void        gimp_palette_editor_pick_col
 void        gimp_palette_editor_zoom       (GimpPaletteEditor  *editor,
                                             GimpZoomType        zoom_type);
 
+gboolean    gimp_palette_editor_go                (GimpPaletteEditor *editor,
+                                                   gint               offset,
+                                                   GimpRGB           *color);
+
+gint        gimp_palette_editor_get_num_entries   (GimpPaletteEditor  *editor);
 
 #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	28 Feb 2006 09:06:20 -0000
@@ -787,3 +787,52 @@ gimp_colormap_image_colormap_changed (Gi
   if (ncol == editor->col_index || ncol == -1)
     gimp_colormap_editor_update_entries (editor);
 }
+
+gint
+gimp_colormap_editor_go(GimpColormapEditor *editor,
+                        gint                offset,
+                        GimpRGB            *color)
+{
+  gint    index;
+  guchar *colormap;
+  guchar  r,g,b;
+
+  if (! HAVE_COLORMAP(GIMP_IMAGE_EDITOR (editor)->gimage))
+    return FALSE;
+  index = editor->col_index;
+
+  colormap = GIMP_IMAGE_EDITOR (editor)->gimage->cmap;
+  gimp_rgb_get_uchar(color, &r,&g,&b);
+
+  if (! (colormap[index * 3] == r && 
+         colormap[index * 3 + 1] == g &&
+         colormap[index * 3 + 2] == b) )
+    {
+      gint j;
+      index = 0;
+      for (j = 0; j <= editor->index_adjustment->upper; j++)
+        {
+          if (colormap[j * 3] == r     && 
+              colormap[j * 3 + 1] == g && 
+              colormap[j * 3 + 2] == b)
+            {
+              index = j;
+              break;
+            }
+        }
+ 
+    }
+
+  index += offset;
+  index = CLAMP (index, 0, editor->index_adjustment->upper);
+  gimp_colormap_editor_set_index (editor, index);
+  gimp_rgb_set_uchar(color, colormap[index * 3], colormap[index * 3 + 1], colormap[index * 3 + 2]);
+  return TRUE;
+}
+
+
+gint
+gimp_colormap_editor_get_num_entries(GimpColormapEditor *editor)
+{
+  return (editor->index_adjustment->upper) + 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	28 Feb 2006 09:06:21 -0000
@@ -72,4 +72,10 @@ void        gimp_colormap_editor_selecte
 gint        gimp_colormap_editor_col_index (GimpColormapEditor *editor);
 
 
+gint        gimp_colormap_editor_go                (GimpColormapEditor *editor,
+                                                    gint                offset,
+                                                    GimpRGB            *color);
+gint        gimp_colormap_editor_get_num_entries   (GimpColormapEditor  *editor);
+
+
 #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	28 Feb 2006 09:06:22 -0000
@@ -33,6 +33,11 @@
 #include "core/gimpdatafactory.h"
 #include "core/gimplist.h"
 
+#include "widgets/gimpdialogfactory.h"
+#include "widgets/gimpsessioninfo.h"
+#include "widgets/gimppaletteeditor.h"
+#include "widgets/gimpcolormapeditor.h"
+
 #include "actions.h"
 #include "context-commands.h"
 
@@ -64,6 +69,9 @@ static const GimpLayerModeEffects paint_
   GIMP_VALUE_MODE
 };
 
+#define MAX_PALETTE_ENTRY 16777216 
+
+
 /*  local function prototypes  */
 
 static void   context_select_object    (GimpActionSelectType  select_type,
@@ -71,6 +79,13 @@ static void   context_select_object    (
                                         GimpContainer        *container);
 static gint   context_paint_mode_index (GimpLayerModeEffects  paint_mode);
 
+static inline GimpPaletteEditor  *context_get_palette_editor ();
+static inline GimpColormapEditor *context_get_colormap_editor();
+static inline gint                context_palette_go (gint     offset, 
+                                                      GimpRGB *color);
+static inline gint          context_max_palette_entry();
+static inline void   context_choose_color_in_palette (gint        value,
+                                                      GimpRGB    *color);
 
 /*  public functions  */
 
@@ -95,6 +110,38 @@ context_colors_swap_cmd_callback (GtkAct
 }
 
 void
+context_foreground_palette_color_cmd_callback(GtkAction *action,
+                                              gint       value,
+                                              gpointer   data)
+{
+  GimpRGB              color; 
+  GimpContext         *context;
+
+  return_if_no_context(context, data);
+
+  gimp_context_get_foreground(context, &color);
+  context_choose_color_in_palette(value, &color);
+  gimp_context_set_foreground(context, &color);
+
+}
+
+void
+context_background_palette_color_cmd_callback(GtkAction *action,
+                                              gint       value,
+                                              gpointer   data)
+{
+  GimpRGB              color; 
+  GimpContext         *context;
+
+  return_if_no_context(context, data);
+
+  gimp_context_get_background(context, &color);
+  context_choose_color_in_palette(value, &color);
+  gimp_context_set_background(context, &color);
+
+}
+
+void
 context_foreground_red_cmd_callback (GtkAction *action,
                                      gint       value,
                                      gpointer   data)
@@ -608,3 +655,143 @@ context_paint_mode_index (GimpLayerModeE
 
   return i;
 }
+
+static inline 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");
+  if (! info)
+    return NULL;
+
+  if (info->widget)
+    palette_editor = gtk_bin_get_child (GTK_BIN (info->widget));
+
+  if (! palette_editor)
+    return NULL;
+  return GIMP_PALETTE_EDITOR(palette_editor);
+
+}
+
+static inline GimpColormapEditor *
+context_get_colormap_editor()
+{
+ GimpDialogFactory *dialog_factory;
+  GimpSessionInfo   *info;
+  GtkWidget         *colormap_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-indexed-palette");
+  if (! info)
+    return NULL;
+  if (info->widget)
+    colormap_editor = gtk_bin_get_child (GTK_BIN (info->widget));
+
+  if (! colormap_editor)
+    return NULL;
+  return GIMP_COLORMAP_EDITOR(colormap_editor);
+
+}
+
+static inline gint
+context_palette_go(gint offset,
+                   GimpRGB *color)
+{
+  GimpPaletteEditor  *peditor;
+  GimpColormapEditor *ceditor;
+
+  ceditor = context_get_colormap_editor();
+  if (ceditor && gimp_colormap_editor_go( ceditor, offset, color))
+    return TRUE;
+  
+  peditor = context_get_palette_editor();
+  if (! peditor)
+    return FALSE;
+
+  gimp_palette_editor_go( peditor, offset, color);
+  return TRUE;
+
+}
+
+
+static inline gint
+context_max_palette_entry()
+{
+  GimpPaletteEditor  *peditor;
+  GimpColormapEditor *ceditor;
+  gint                entries;
+
+
+  ceditor = context_get_colormap_editor();
+  if (ceditor)
+    {
+      entries = gimp_colormap_editor_get_num_entries(ceditor);
+      if (entries != -1)
+        return entries - 1;
+    }
+
+  peditor = context_get_palette_editor();
+  if (! peditor)
+    return 0;
+  return gimp_palette_editor_get_num_entries(peditor);
+
+}
+
+static void
+context_choose_color_in_palette(gint        value,
+                                GimpRGB     *color)
+{
+  GimpActionSelectType select_type = (GimpActionSelectType) value;
+  gint                 max;
+  gdouble              tmp;
+
+  switch (select_type)
+    {
+      case GIMP_ACTION_SELECT_FIRST:
+        context_palette_go(-MAX_PALETTE_ENTRY, color);
+        break;
+
+      case GIMP_ACTION_SELECT_LAST:
+        context_palette_go(MAX_PALETTE_ENTRY, color);
+        break;
+
+      case GIMP_ACTION_SELECT_NEXT:
+        context_palette_go(1, color);
+        break;
+
+      case GIMP_ACTION_SELECT_PREVIOUS:
+        context_palette_go(-1, color);
+        break;
+
+      case GIMP_ACTION_SELECT_SKIP_NEXT:
+        context_palette_go(4, color);
+        break;
+
+      case GIMP_ACTION_SELECT_SKIP_PREVIOUS:
+        context_palette_go(-4, color);
+        break;
+
+      default: /* SELECT_SET */
+        max = context_max_palette_entry();
+        context_palette_go(-MAX_PALETTE_ENTRY, color);
+        tmp = action_select_value( select_type, 
+                                   (gdouble) ((max * 16) / 2),
+                                   0.0,
+                                   (gdouble) max * 16,
+                                   1.0,
+                                   4.0, /* tweak this */
+                                   FALSE );
+        tmp = tmp / 16.0;
+        tmp -= (gdouble) (max / 2);
+        context_palette_go((gint) tmp, color);
+        break;
+    }
+
+}
+
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	28 Feb 2006 09:06:22 -0000
@@ -20,11 +20,19 @@
 #define __CONTEXT_COMMANDS_H__
 
 
+
 void   context_colors_default_cmd_callback  (GtkAction   *action,
                                              gpointer     data);
 void   context_colors_swap_cmd_callback     (GtkAction   *action,
                                              gpointer     data);
 
+void   context_foreground_palette_color_cmd_callback( GtkAction *action,
+                                                      gint       value,
+                                                      gpointer   data);
+void   context_background_palette_color_cmd_callback( GtkAction *action,
+                                                      gint       value,
+                                                      gpointer   data);
+
 void   context_foreground_red_cmd_callback  (GtkAction *action,
                                              gint       value,
                                              gpointer   data);
@@ -109,6 +117,7 @@ void   context_brush_aspect_cmd_callback
 void   context_brush_angle_cmd_callback     (GtkAction *action,
                                              gint       value,
                                              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	28 Feb 2006 09:06:23 -0000
@@ -69,9 +69,74 @@ 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 },
 };
 
+static GimpEnumActionEntry context_foreground_palette_actions[] =
+{
+  { "context-foreground-palette-color-set", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color Set"), NULL, NULL,
+    GIMP_ACTION_SELECT_SET, FALSE,
+    NULL },
+  { "context-foreground-palette-color-minimum", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color First"), NULL, NULL,
+    GIMP_ACTION_SELECT_FIRST, FALSE,
+    NULL },
+  { "context-foreground-palette-color-maximum", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color Last"), NULL, NULL,
+    GIMP_ACTION_SELECT_LAST, FALSE,
+    NULL },
+  { "context-foreground-palette-color-decrease", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color Previous"), "9", NULL,
+    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
+    NULL },
+  { "context-foreground-palette-color-increase", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color Next"), "0", NULL,
+    GIMP_ACTION_SELECT_NEXT, FALSE,
+    NULL },
+  { "context-foreground-palette-color-decrease-skip", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color Skip Back"), NULL, NULL,
+    GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
+    NULL },
+  { "context-foreground-palette-color-increase-skip", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Foreground Palette color Skip Forward"), NULL, NULL,
+    GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
+    NULL }
+};
+
+static GimpEnumActionEntry context_background_palette_actions[] =
+{
+  { "context-background-palette-color-set", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color Set"), NULL, NULL,
+    GIMP_ACTION_SELECT_SET, FALSE,
+    NULL },
+  { "context-background-palette-color-minimum", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color First"), NULL, NULL,
+    GIMP_ACTION_SELECT_FIRST, FALSE,
+    NULL },
+  { "context-background-palette-color-maximum", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color Last"), NULL, NULL,
+    GIMP_ACTION_SELECT_LAST, FALSE,
+    NULL },
+  { "context-background-palette-color-decrease", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color Previous"), NULL, NULL,
+    GIMP_ACTION_SELECT_PREVIOUS, FALSE,
+    NULL },
+  { "context-background-palette-color-increase", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color Next"), NULL, NULL,
+    GIMP_ACTION_SELECT_NEXT, FALSE,
+    NULL },
+  { "context-background-palette-color-decrease-skip", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color Skip Back"), NULL, NULL,
+    GIMP_ACTION_SELECT_SKIP_PREVIOUS, FALSE,
+    NULL },
+  { "context-background-palette-color-increase-skip", GIMP_STOCK_INDEXED_PALETTE,
+    N_("Background Palette color Skip ahead"), NULL, NULL,
+    GIMP_ACTION_SELECT_SKIP_NEXT, FALSE,
+    NULL }
+};
+
+
 static GimpEnumActionEntry context_foreground_red_actions[] =
 {
   { "context-foreground-red-set", GIMP_STOCK_CHANNEL_RED,
@@ -835,6 +900,16 @@ context_actions_setup (GimpActionGroup *
   gimp_action_group_add_actions (group,
                                  context_actions,
                                  G_N_ELEMENTS (context_actions));
+
+  gimp_action_group_add_enum_actions (group,
+                                      context_foreground_palette_actions,
+                                      G_N_ELEMENTS (context_foreground_palette_actions),
+                                      G_CALLBACK (context_foreground_palette_color_cmd_callback));
+  gimp_action_group_add_enum_actions (group,
+                                      context_background_palette_actions,
+                                      G_N_ELEMENTS (context_background_palette_actions),
+                                      G_CALLBACK (context_background_palette_color_cmd_callback));
+
 
   gimp_action_group_add_enum_actions (group,
                                       context_foreground_red_actions,
