[gnome-commander/gcmd-1-3] Support for user defined LS_COLORS colours



commit aaaa44854e458e56e350ae3a6396e3930d39d26c
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Wed Dec 16 17:03:45 2009 +0100

    Support for user defined LS_COLORS colours

 src/gnome-cmd-data.cc           |   65 +++++++++++++-
 src/gnome-cmd-data.h            |    2 +
 src/gnome-cmd-options-dialog.cc |  183 ++++++++++++++++++++++++++++++++++++++-
 src/gnome-cmd-types.h           |   13 +++
 src/ls_colors.cc                |   53 +++++-------
 src/main.cc                     |    2 +-
 6 files changed, 284 insertions(+), 34 deletions(-)
---
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 6fa5a84..7bf1744 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -69,6 +69,8 @@ struct GnomeCmdData::Private
     gchar                *symlink_prefix;
 
     gchar                *ftp_anonymous_password;
+
+    GnomeCmdLsColorsPalette ls_colors_palette;
 };
 
 
@@ -1272,6 +1274,25 @@ void GnomeCmdData::load()
     gnome_cmd_data_get_color ("/colors/curs_fg", priv->color_themes[GNOME_CMD_COLOR_CUSTOM].curs_fg);
     gnome_cmd_data_get_color ("/colors/curs_bg", priv->color_themes[GNOME_CMD_COLOR_CUSTOM].curs_bg);
 
+    use_ls_colors = gnome_cmd_data_get_bool ("/colors/use_ls_colors", FALSE);
+
+    priv->ls_colors_palette.black_fg = gdk_color_new (0, 0, 0);
+    priv->ls_colors_palette.black_bg = gdk_color_new (0, 0, 0);
+    priv->ls_colors_palette.red_fg = gdk_color_new (0xffff, 0, 0);
+    priv->ls_colors_palette.red_bg = gdk_color_new (0xffff, 0, 0);
+    priv->ls_colors_palette.green_fg = gdk_color_new (0, 0xffff, 0);
+    priv->ls_colors_palette.green_bg = gdk_color_new (0, 0xffff, 0);
+    priv->ls_colors_palette.yellow_fg = gdk_color_new (0xffff, 0xffff, 0);
+    priv->ls_colors_palette.yellow_bg = gdk_color_new (0xffff, 0xffff, 0);
+    priv->ls_colors_palette.blue_fg = gdk_color_new (0, 0, 0xffff);
+    priv->ls_colors_palette.blue_bg = gdk_color_new (0, 0, 0xffff);
+    priv->ls_colors_palette.magenta_fg = gdk_color_new (0xffff, 0, 0xffff);
+    priv->ls_colors_palette.magenta_bg = gdk_color_new (0xffff, 0, 0xffff);
+    priv->ls_colors_palette.cyan_fg = gdk_color_new (0, 0xffff, 0xffff);
+    priv->ls_colors_palette.cyan_bg = gdk_color_new (0, 0xffff, 0xffff);
+    priv->ls_colors_palette.white_fg = gdk_color_new (0xffff, 0xffff, 0xffff);
+    priv->ls_colors_palette.white_bg = gdk_color_new (0xffff, 0xffff, 0xffff);
+
     priv->list_font = gnome_cmd_data_get_string ("/options/list_font", "-misc-fixed-medium-r-normal-*-10-*-*-*-c-*-iso8859-1");
 
     ext_disp_mode = (GnomeCmdExtDispMode) gnome_cmd_data_get_int ("/options/ext_disp_mode", GNOME_CMD_EXT_DISP_BOTH);
@@ -1330,7 +1351,23 @@ void GnomeCmdData::load()
     use_gcmd_block = gnome_cmd_data_get_bool ("/programs/use_gcmd_block", FALSE);
 
     device_only_icon = gnome_cmd_data_get_bool ("/devices/only_icon", FALSE);
-    use_ls_colors = gnome_cmd_data_get_bool ("/colors/use_ls_colors", FALSE);
+
+    gnome_cmd_data_get_color ("/colors/ls_colors_black_fg", priv->ls_colors_palette.black_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_black_bg", priv->ls_colors_palette.black_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_red_fg", priv->ls_colors_palette.red_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_red_bg", priv->ls_colors_palette.red_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_green_fg", priv->ls_colors_palette.green_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_green_bg", priv->ls_colors_palette.green_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_yellow_fg", priv->ls_colors_palette.yellow_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_yellow_bg", priv->ls_colors_palette.yellow_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_blue_fg", priv->ls_colors_palette.blue_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_blue_bg", priv->ls_colors_palette.blue_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_magenta_fg", priv->ls_colors_palette.magenta_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_magenta_bg", priv->ls_colors_palette.magenta_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_cyan_fg", priv->ls_colors_palette.cyan_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_cyan_bg", priv->ls_colors_palette.cyan_bg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_white_fg", priv->ls_colors_palette.white_fg);
+    gnome_cmd_data_get_color ("/colors/ls_colors_white_bg", priv->ls_colors_palette.white_bg);
 
     priv->start_dirs[LEFT] = gnome_cmd_data_get_string ("/options/start_dir_left", g_get_home_dir ());
     priv->start_dirs[RIGHT] = gnome_cmd_data_get_string ("/options/start_dir_right", g_get_home_dir ());
@@ -1647,6 +1684,25 @@ void GnomeCmdData::save()
     gnome_cmd_data_set_color  ("/colors/curs_fg", priv->color_themes[GNOME_CMD_COLOR_CUSTOM].curs_fg);
     gnome_cmd_data_set_color  ("/colors/curs_bg", priv->color_themes[GNOME_CMD_COLOR_CUSTOM].curs_bg);
 
+    gnome_cmd_data_set_bool   ("/colors/use_ls_colors", use_ls_colors);
+
+    gnome_cmd_data_set_color ("/colors/ls_colors_black_fg", priv->ls_colors_palette.black_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_black_bg", priv->ls_colors_palette.black_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_red_fg", priv->ls_colors_palette.red_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_red_bg", priv->ls_colors_palette.red_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_green_fg", priv->ls_colors_palette.green_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_green_bg", priv->ls_colors_palette.green_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_yellow_fg", priv->ls_colors_palette.yellow_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_yellow_bg", priv->ls_colors_palette.yellow_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_blue_fg", priv->ls_colors_palette.blue_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_blue_bg", priv->ls_colors_palette.blue_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_magenta_fg", priv->ls_colors_palette.magenta_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_magenta_bg", priv->ls_colors_palette.magenta_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_cyan_fg", priv->ls_colors_palette.cyan_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_cyan_bg", priv->ls_colors_palette.cyan_bg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_white_fg", priv->ls_colors_palette.white_fg);
+    gnome_cmd_data_set_color ("/colors/ls_colors_white_bg", priv->ls_colors_palette.white_bg);
+
     gnome_cmd_data_set_string ("/options/list_font", priv->list_font);
 
     gnome_cmd_data_set_int    ("/options/ext_disp_mode", ext_disp_mode);
@@ -1697,7 +1753,6 @@ void GnomeCmdData::save()
     gnome_cmd_data_set_bool   ("/programs/use_gcmd_block", use_gcmd_block);
 
     gnome_cmd_data_set_bool   ("/devices/only_icon", device_only_icon);
-    gnome_cmd_data_set_bool   ("/colors/use_ls_colors", use_ls_colors);
 
     const gchar *quick_connect_uri = gnome_cmd_con_get_uri (GNOME_CMD_CON (quick_connect));
 
@@ -1846,6 +1901,12 @@ GnomeCmdColorTheme *gnome_cmd_data_get_custom_color_theme ()
 }
 
 
+GnomeCmdLsColorsPalette *gnome_cmd_data_get_ls_colors_palette ()
+{
+    return &gnome_cmd_data.priv->ls_colors_palette;
+}
+
+
 const gchar *gnome_cmd_data_get_list_font ()
 {
     return gnome_cmd_data.priv->list_font;
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 24e5a66..b375c8a 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -280,6 +280,8 @@ void gnome_cmd_data_set_date_format (GnomeCmdDateFormat format);
 GnomeCmdColorTheme *gnome_cmd_data_get_custom_color_theme ();
 GnomeCmdColorTheme *gnome_cmd_data_get_current_color_theme ();
 
+GnomeCmdLsColorsPalette *gnome_cmd_data_get_ls_colors_palette ();
+
 void gnome_cmd_data_get_sort_params (GnomeCmdFileList *fl, gint &col, gboolean &direction);
 void gnome_cmd_data_set_sort_params (GnomeCmdFileList *fl, gint col, gboolean direction);
 
diff --git a/src/gnome-cmd-options-dialog.cc b/src/gnome-cmd-options-dialog.cc
index 396724d..78ea056 100644
--- a/src/gnome-cmd-options-dialog.cc
+++ b/src/gnome-cmd-options-dialog.cc
@@ -427,6 +427,178 @@ static void on_colors_edit (GtkButton *btn, GtkWidget *parent)
 }
 
 
+static void on_ls_colors_toggled (GtkToggleButton *btn, GtkWidget *dialog)
+{
+    GtkWidget *edit_btn = lookup_widget (GTK_WIDGET (dialog), "ls_colors_edit_btn");
+    if (edit_btn)
+        gtk_widget_set_sensitive (edit_btn, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (btn)));
+}
+
+
+static void on_edit_ls_colors_cancel (GtkButton *btn, GtkWidget *dlg)
+{
+    gtk_widget_destroy (dlg);
+}
+
+
+static void on_edit_ls_colors_ok (GtkButton *btn, GtkWidget *dlg)
+{
+    GnomeCmdLsColorsPalette *palette = gnome_cmd_data_get_ls_colors_palette ();
+
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "black_fg")), palette->black_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "black_bg")), palette->black_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "red_fg")), palette->red_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "red_bg")), palette->red_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "green_fg")), palette->green_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "green_bg")), palette->green_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "yellow_fg")), palette->yellow_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "yellow_bg")), palette->yellow_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "blue_fg")), palette->blue_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "blue_bg")), palette->blue_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "magenta_fg")), palette->magenta_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "magenta_bg")), palette->magenta_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "cyan_fg")), palette->cyan_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "cyan_bg")), palette->cyan_bg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "white_fg")), palette->white_fg);
+    gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "white_bg")), palette->white_bg);
+
+    gtk_widget_destroy (dlg);
+}
+
+
+static void on_edit_ls_colors_reset (GtkButton *btn, GtkWidget *dlg)
+{
+    static GdkColor black   = {0,0,0,0};
+    static GdkColor red     = {0,0xffff,0,0};
+    static GdkColor green   = {0,0,0xffff,0};
+    static GdkColor yellow  = {0,0xffff,0xffff,0};
+    static GdkColor blue    = {0,0,0,0xffff};
+    static GdkColor magenta = {0,0xffff,0,0xffff};
+    static GdkColor cyan    = {0,0,0xffff,0xffff};
+    static GdkColor white   = {0,0xffff,0xffff,0xffff};
+
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "black_fg")), &black);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "black_bg")), &black);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "red_fg")), &red);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "red_bg")), &red);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "green_fg")), &green);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "green_bg")), &green);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "yellow_fg")), &yellow);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "yellow_bg")), &yellow);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "blue_fg")), &blue);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "blue_bg")), &blue);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "magenta_fg")), &magenta);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "magenta_bg")), &magenta);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "cyan_fg")), &cyan);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "cyan_bg")), &cyan);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "white_fg")), &white);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "white_bg")), &white);
+}
+
+
+static void on_ls_colors_edit (GtkButton *btn, GtkWidget *parent)
+{
+    GtkWidget *dlg = gnome_cmd_dialog_new (_("Edit LS_COLORS Palette"));
+    gtk_widget_ref (dlg);
+
+    GtkWidget *cat, *cat_box;
+    GtkWidget *table, *label;
+    GtkWidget *cbutton;
+    GnomeCmdLsColorsPalette *palette = gnome_cmd_data_get_ls_colors_palette ();
+
+    cat_box = create_vbox (dlg, FALSE, 12);
+    cat = create_category (dlg, cat_box, _("Palette"));
+    gnome_cmd_dialog_add_category (GNOME_CMD_DIALOG (dlg), cat);
+
+    table = create_table (dlg, 3, 9);
+    gtk_container_add (GTK_CONTAINER (cat_box), table);
+
+    cbutton = create_color_button (dlg, "black_fg");
+    table_add (table, cbutton, 1, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->black_fg);
+    cbutton = create_color_button (dlg, "black_bg");
+    table_add (table, cbutton, 1, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->black_bg);
+    cbutton = create_color_button (dlg, "red_fg");
+    table_add (table, cbutton, 2, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->red_fg);
+    cbutton = create_color_button (dlg, "red_bg");
+    table_add (table, cbutton, 2, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->red_bg);
+    cbutton = create_color_button (dlg, "green_fg");
+    table_add (table, cbutton, 3, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->green_fg);
+    cbutton = create_color_button (dlg, "green_bg");
+    table_add (table, cbutton, 3, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->green_bg);
+    cbutton = create_color_button (dlg, "yellow_fg");
+    table_add (table, cbutton, 4, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->yellow_fg);
+    cbutton = create_color_button (dlg, "yellow_bg");
+    table_add (table, cbutton, 4, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->yellow_bg);
+    cbutton = create_color_button (dlg, "blue_fg");
+    table_add (table, cbutton, 5, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->blue_fg);
+    cbutton = create_color_button (dlg, "blue_bg");
+    table_add (table, cbutton, 5, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->blue_bg);
+    cbutton = create_color_button (dlg, "magenta_fg");
+    table_add (table, cbutton, 6, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->magenta_fg);
+    cbutton = create_color_button (dlg, "magenta_bg");
+    table_add (table, cbutton, 6, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->magenta_bg);
+    cbutton = create_color_button (dlg, "cyan_fg");
+    table_add (table, cbutton, 7, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->cyan_fg);
+    cbutton = create_color_button (dlg, "cyan_bg");
+    table_add (table, cbutton, 7, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->cyan_bg);
+    cbutton = create_color_button (dlg, "white_fg");
+    table_add (table, cbutton, 8, 1, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->white_fg);
+    cbutton = create_color_button (dlg, "white_bg");
+    table_add (table, cbutton, 8, 2, (GtkAttachOptions) 0);
+    gtk_color_button_set_color (GTK_COLOR_BUTTON (cbutton), palette->white_bg);
+
+    label = create_label (dlg, _("Foreground:"));
+    table_add (table, label, 0, 1, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Background:"));
+    table_add (table, label, 0, 2, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Black"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 1, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Red"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 2, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Green"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 3, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Yellow"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 4, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Blue"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 5, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Magenta"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 6, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("Cyan"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 7, 0, (GtkAttachOptions) GTK_FILL);
+    label = create_label (dlg, _("White"));
+    gtk_misc_set_alignment (GTK_MISC (label), 0.5, 1.0);
+    table_add (table, label, 8, 0, (GtkAttachOptions) GTK_FILL);
+
+    gnome_cmd_dialog_add_button (GNOME_CMD_DIALOG (dlg), _("_Reset"), GTK_SIGNAL_FUNC (on_edit_ls_colors_reset), dlg);
+    gnome_cmd_dialog_add_button (GNOME_CMD_DIALOG (dlg), GTK_STOCK_CANCEL, GTK_SIGNAL_FUNC (on_edit_ls_colors_cancel), dlg);
+    gnome_cmd_dialog_add_button (GNOME_CMD_DIALOG (dlg), GTK_STOCK_OK, GTK_SIGNAL_FUNC (on_edit_ls_colors_ok), dlg);
+
+    gtk_widget_show (dlg);
+}
+
+
 static GtkWidget *create_layout_tab (GtkWidget *parent)
 {
     GtkWidget *frame, *hbox, *vbox, *cat;
@@ -519,7 +691,16 @@ static GtkWidget *create_layout_tab (GtkWidget *parent)
     // LS_COLORS
     check = create_check (parent, _("Colorize files according to the LS_COLORS environment variable"), "use_ls_colors");
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), gnome_cmd_data.use_ls_colors);
-    gtk_table_attach (GTK_TABLE (table), check, 0, 2, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
+    hbox = create_hbox (parent, FALSE, 6);
+    gtk_table_attach (GTK_TABLE (table), hbox, 0, 2, 5, 6, GTK_FILL, GTK_FILL, 0, 0);
+
+    gtk_signal_connect (GTK_OBJECT (check), "toggled", GTK_SIGNAL_FUNC (on_ls_colors_toggled), parent);
+    gtk_box_pack_start (GTK_BOX (hbox), check, TRUE, TRUE, 0);
+
+    btn = create_button_with_data (parent, _("Edit colors..."), GTK_SIGNAL_FUNC (on_ls_colors_edit), parent);
+    g_object_set_data (G_OBJECT (parent), "ls_colors_edit_btn", btn);
+    gtk_box_pack_start (GTK_BOX (hbox), btn, FALSE, TRUE, 0);
+    gtk_widget_set_sensitive (btn, gnome_cmd_data.use_ls_colors);
 
 
      // MIME icon settings
diff --git a/src/gnome-cmd-types.h b/src/gnome-cmd-types.h
index 6bfe66f..13c1cfd 100644
--- a/src/gnome-cmd-types.h
+++ b/src/gnome-cmd-types.h
@@ -85,6 +85,19 @@ struct GnomeCmdColorTheme
 };
 
 
+struct GnomeCmdLsColorsPalette
+{
+    GdkColor *black_fg, *black_bg;
+    GdkColor *red_fg, *red_bg;
+    GdkColor *green_fg, *green_bg;
+    GdkColor *yellow_fg, *yellow_bg;
+    GdkColor *blue_fg, *blue_bg;
+    GdkColor *magenta_fg, *magenta_bg;
+    GdkColor *cyan_fg, *cyan_bg;
+    GdkColor *white_fg, *white_bg;
+};
+
+
 struct GnomeCmdCon;
 
 
diff --git a/src/ls_colors.cc b/src/ls_colors.cc
index d2bd447..b8ea540 100644
--- a/src/ls_colors.cc
+++ b/src/ls_colors.cc
@@ -23,6 +23,7 @@
 #include "gnome-cmd-includes.h"
 #include "ls_colors.h"
 #include "gnome-cmd-file.h"
+#include "gnome-cmd-data.h"
 
 using namespace std;
 
@@ -33,16 +34,6 @@ using namespace std;
 static GHashTable *map;
 static LsColor *type_colors[8];
 
-static GdkColor black   = {0,0,0,0};
-static GdkColor red     = {0,0xffff,0,0};
-static GdkColor green   = {0,0,0xffff,0};
-static GdkColor yellow  = {0,0xffff,0xffff,0};
-static GdkColor blue    = {0,0,0,0xffff};
-static GdkColor magenta = {0,0xffff,0,0xffff};
-static GdkColor cyan    = {0,0,0xffff,0xffff};
-static GdkColor white   = {0,0xffff,0xffff,0xffff};
-
-
 
 /*
 # Attribute codes:
@@ -54,25 +45,27 @@ static GdkColor white   = {0,0xffff,0xffff,0xffff};
 */
 inline GdkColor *code2color (gint code)
 {
+    GnomeCmdLsColorsPalette *palette = gnome_cmd_data_get_ls_colors_palette ();
+
     switch (code)
     {
-        case 30: return &black;
-        case 31: return &red;
-        case 32: return &green;
-        case 33: return &yellow;
-        case 34: return &blue;
-        case 35: return &magenta;
-        case 36: return &cyan;
-        case 37: return &white;
-
-        case 40: return &black;
-        case 41: return &red;
-        case 42: return &green;
-        case 43: return &yellow;
-        case 44: return &blue;
-        case 45: return &magenta;
-        case 46: return &cyan;
-        case 47: return &white;
+        case 30: return palette->black_fg;
+        case 31: return palette->red_fg;
+        case 32: return palette->green_fg;
+        case 33: return palette->yellow_fg;
+        case 34: return palette->blue_fg;
+        case 35: return palette->magenta_fg;
+        case 36: return palette->cyan_fg;
+        case 37: return palette->white_fg;
+
+        case 40: return palette->black_bg;
+        case 41: return palette->red_bg;
+        case 42: return palette->green_bg;
+        case 43: return palette->yellow_bg;
+        case 44: return palette->blue_bg;
+        case 45: return palette->magenta_bg;
+        case 46: return palette->cyan_bg;
+        case 47: return palette->white_bg;
     }
 
     return NULL;
@@ -184,7 +177,7 @@ static void init (gchar *ls_colors)
         if (col)
         {
             if (col->ext)
-                g_hash_table_insert (map, col->ext, col);
+                g_hash_table_insert (::map, col->ext, col);
             else
                 type_colors[col->type] = col;
         }
@@ -200,7 +193,7 @@ void ls_colors_init ()
     if (!s)
         s = DEFAULT_COLORS;
 
-    map = g_hash_table_new (g_str_hash, g_str_equal);
+    ::map = g_hash_table_new (g_str_hash, g_str_equal);
     init (s);
 }
 
@@ -214,7 +207,7 @@ LsColor *ls_colors_get (GnomeCmdFile *f)
     const gchar *ext = gnome_cmd_file_get_extension (f);
 
     if (ext)
-        col = (LsColor *) g_hash_table_lookup (map, ext);
+        col = (LsColor *) g_hash_table_lookup (::map, ext);
 
     if (!col)
         col = type_colors[f->info->type];
diff --git a/src/main.cc b/src/main.cc
index aef28bd..b2fd950 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -117,7 +117,6 @@ int main (int argc, char *argv[])
                                   GNOME_PARAM_APP_DATADIR, DATADIR,
                                   GNOME_PARAM_NONE);
 
-    ls_colors_init ();
     gdk_rgb_init ();
     gnome_vfs_init ();
 
@@ -127,6 +126,7 @@ int main (int argc, char *argv[])
     gcmd_user_actions.init();
     gnome_cmd_data.load();
     gcmd_user_actions.set_defaults();
+    ls_colors_init ();
     IMAGE_init ();
     gnome_cmd_data.load_more();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]