From 3eb498c0b538678cc8be7d4c4321275790986e21 Mon Sep 17 00:00:00 2001 From: Bhaskar Bhat Date: Fri, 25 Nov 2011 20:26:52 +0530 Subject: [PATCH 2/3] Improvement Version 2 --- src/gnome-cmd-options-dialog.cc | 11 ++++++ src/gnome-cmd-types.h | 66 +++++++++++++++++++++++++++++++++++++++ src/gnome-cmd-user-actions.cc | 8 +++- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/gnome-cmd-options-dialog.cc b/src/gnome-cmd-options-dialog.cc index aa70f8a..dd32e77 100644 --- a/src/gnome-cmd-options-dialog.cc +++ b/src/gnome-cmd-options-dialog.cc @@ -464,6 +464,9 @@ static void on_edit_colors_close (GtkButton *btn, GtkWidget *dlg) gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "cursor_fg")), colors->curs_fg); gtk_color_button_get_color (GTK_COLOR_BUTTON (lookup_widget (dlg, "cursor_bg")), colors->curs_bg); + gnome_cmd_style_create (gnome_cmd_data.options); + main_win->update_style (); + gtk_widget_destroy (dlg); } @@ -539,6 +542,11 @@ 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))); + + gnome_cmd_data.options.use_ls_colors = gtk_toggle_button_get_active (btn); + + gnome_cmd_style_create (gnome_cmd_data.options); + main_win->update_style (); } @@ -569,6 +577,9 @@ static void on_edit_ls_colors_ok (GtkButton *btn, GtkWidget *dlg) 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); + gnome_cmd_style_create (gnome_cmd_data.options); + main_win->update_style (); + gtk_widget_destroy (dlg); } diff --git a/src/gnome-cmd-types.h b/src/gnome-cmd-types.h index 650c31b..97622fa 100644 --- a/src/gnome-cmd-types.h +++ b/src/gnome-cmd-types.h @@ -152,8 +152,74 @@ struct GnomeCmdLsColorsPalette GdkColor *magenta_fg, *magenta_bg; GdkColor *cyan_fg, *cyan_bg; GdkColor *white_fg, *white_bg; + + GnomeCmdLsColorsPalette () + { + black_fg = NULL; + black_bg = NULL; + red_fg = NULL; + red_bg = NULL; + green_fg = NULL; + green_bg = NULL; + yellow_fg = NULL; + yellow_bg = NULL; + blue_fg = NULL; + blue_bg = NULL; + magenta_fg = NULL; + magenta_bg = NULL; + cyan_fg = NULL; + cyan_bg = NULL; + white_fg = NULL; + white_bg = NULL; + } + + ~GnomeCmdLsColorsPalette () + { + if (black_fg) gdk_color_free (black_fg); + if (black_bg) gdk_color_free (black_bg); + if (red_fg) gdk_color_free (red_fg); + if (red_bg) gdk_color_free (red_bg); + if (green_fg) gdk_color_free (green_fg); + if (green_bg) gdk_color_free (green_bg); + if (yellow_fg) gdk_color_free (yellow_fg); + if (yellow_bg) gdk_color_free (yellow_bg); + if (blue_fg) gdk_color_free (blue_fg); + if (blue_bg) gdk_color_free (blue_bg); + if (magenta_fg) gdk_color_free (magenta_fg); + if (magenta_bg) gdk_color_free (magenta_bg); + if (cyan_fg) gdk_color_free (cyan_fg); + if (cyan_bg) gdk_color_free (cyan_bg); + if (white_fg) gdk_color_free (white_fg); + if (white_bg) gdk_color_free (white_bg); + } + + GnomeCmdLsColorsPalette &operator = (const GnomeCmdLsColorsPalette &palette); }; +inline GnomeCmdLsColorsPalette &GnomeCmdLsColorsPalette::operator = (const GnomeCmdLsColorsPalette &palette) +{ + if (this != &palette) + { + black_fg = gdk_color_copy (palette.black_fg); + black_bg = gdk_color_copy (palette.black_bg); + red_fg = gdk_color_copy (palette.red_fg); + red_bg = gdk_color_copy (palette.red_bg); + green_fg = gdk_color_copy (palette.green_fg); + green_bg = gdk_color_copy (palette.green_bg); + yellow_fg = gdk_color_copy (palette.yellow_fg); + yellow_bg = gdk_color_copy (palette.yellow_bg); + blue_fg = gdk_color_copy (palette.blue_fg); + blue_bg = gdk_color_copy (palette.blue_bg); + magenta_fg = gdk_color_copy (palette.magenta_fg); + magenta_bg = gdk_color_copy (palette.magenta_bg); + cyan_fg = gdk_color_copy (palette.cyan_fg); + cyan_bg = gdk_color_copy (palette.cyan_bg); + white_fg = gdk_color_copy (palette.white_fg); + white_bg = gdk_color_copy (palette.white_bg); + } + return *this; +} + struct GnomeCmdCon; diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc index 66d36ee..6d12eee 100644 --- a/src/gnome-cmd-user-actions.cc +++ b/src/gnome-cmd-user-actions.cc @@ -1790,16 +1790,20 @@ void view_toggle_tab_lock (GtkMenuItem *menuitem, gpointer page) /************** Options Menu **************/ void options_edit (GtkMenuItem *menuitem, gpointer not_used) { + GnomeCmdData::Options prev_options (gnome_cmd_data.options); + if (gnome_cmd_options_dialog (*main_win, gnome_cmd_data.options)) { gnome_cmd_style_create (gnome_cmd_data.options); main_win->update_style(); - - gnome_cmd_data.save(); + gnome_cmd_data.save(); } else { //Revert back the changes done + gnome_cmd_data.options = prev_options; + gnome_cmd_style_create (gnome_cmd_data.options); + main_win->update_style (); } } -- 1.7.7.3