[anjuta-extras] scintilla: Improve style setting dialog
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta-extras] scintilla: Improve style setting dialog
- Date: Thu, 29 Sep 2011 20:38:13 +0000 (UTC)
commit 9f8cea642d4d4aea0ca5ec364d74c09dc2811e50
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Thu Sep 29 22:37:40 2011 +0200
scintilla: Improve style setting dialog
plugins/scintilla/anjuta-editor-scintilla.ui | 21 +--
plugins/scintilla/style-editor.c | 367 ++++++++++++++++----------
2 files changed, 234 insertions(+), 154 deletions(-)
---
diff --git a/plugins/scintilla/anjuta-editor-scintilla.ui b/plugins/scintilla/anjuta-editor-scintilla.ui
index 5767cef..06e4d59 100644
--- a/plugins/scintilla/anjuta-editor-scintilla.ui
+++ b/plugins/scintilla/anjuta-editor-scintilla.ui
@@ -1802,22 +1802,6 @@
</child>
<child>
<object class="GtkButton" id="button2">
- <property name="label">gtk-apply</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <object class="GtkButton" id="button3">
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -1829,7 +1813,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -1844,8 +1828,7 @@
</child>
<action-widgets>
<action-widget response="-6">button1</action-widget>
- <action-widget response="-10">button2</action-widget>
- <action-widget response="-5">button3</action-widget>
+ <action-widget response="-5">button2</action-widget>
</action-widgets>
</object>
</interface>
diff --git a/plugins/scintilla/style-editor.c b/plugins/scintilla/style-editor.c
index dbd5bc3..f2d28c9 100644
--- a/plugins/scintilla/style-editor.c
+++ b/plugins/scintilla/style-editor.c
@@ -71,9 +71,8 @@ struct _StyleData
gchar *item;
gchar *font;
gint size;
- gboolean bold, italics, underlined;
+ gboolean bold, italics, underlined, eolfilled;
gchar *fore, *back;
- gboolean eolfilled;
gboolean font_use_default;
gboolean attrib_use_default;
@@ -104,6 +103,9 @@ struct _StyleEditorPriv
/* Data */
StyleData *default_style;
StyleData *current_style;
+
+ /* Save all properties */
+ GList *saved_props;
};
static gchar *
@@ -408,9 +410,15 @@ style_data_new_parse (gchar * style_string)
style_data->font_use_default = FALSE;
}
if (0 == strcmp (opt, "eolfilled"))
+ {
style_data->eolfilled = TRUE;
+ style_data->attrib_use_default = FALSE;
+ }
if (0 == strcmp (opt, "noteolfilled"))
+ {
style_data->eolfilled = FALSE;
+ style_data->attrib_use_default = FALSE;
+ }
if (0 == strcmp (opt, "underlined"))
{
style_data->underlined = TRUE;
@@ -419,7 +427,7 @@ style_data_new_parse (gchar * style_string)
if (0 == strcmp (opt, "notunderlined"))
{
style_data->underlined = FALSE;
- style_data->fore_use_default = FALSE;
+ style_data->attrib_use_default = FALSE;
}
if (cpComma)
opt = cpComma + 1;
@@ -431,6 +439,167 @@ style_data_new_parse (gchar * style_string)
return style_data;
}
+static void
+sync_from_props (StyleEditor *se)
+{
+ gint i;
+ gchar *str;
+
+ g_return_if_fail (se);
+ /* Never hurts to use g_object_*_data as temp hash buffer */
+ for (i = 0;; i += 2)
+ {
+ StyleData *sdata;
+
+ if (hilite_style[i] == NULL)
+ break;
+ str = sci_prop_get_expanded (se->props, hilite_style[i + 1]);
+ sdata = style_data_new_parse (str);
+ /* DEBUG_PRINT ("Parsing %s => %s", hilite_style[i + 1], str); */
+ if (str)
+ g_free (str);
+
+ style_data_set_item (sdata, hilite_style[i]);
+ g_object_set_data_full (G_OBJECT (se->priv->dialog),
+ hilite_style[i], sdata,
+ (GDestroyNotify)style_data_destroy);
+ }
+ se->priv->default_style =
+ g_object_get_data (G_OBJECT (se->priv->dialog),
+ hilite_style[0]);
+ se->priv->current_style = NULL;
+
+ str = sci_prop_get (se->props, CARET_FORE_COLOR);
+ if(str)
+ {
+ GdkColor color;
+
+ gdk_color_parse (str, &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->caret_fore_color),
+ &color);
+ g_free (str);
+ }
+ else
+ {
+ GdkColor color;
+
+ gdk_color_parse ("#000000", &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->caret_fore_color),
+ &color);
+ }
+
+ str = sci_prop_get (se->props, CALLTIP_BACK_COLOR);
+ if(str)
+ {
+ GdkColor color;
+
+ gdk_color_parse (str, &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->calltip_back_color),
+ &color);
+ g_free (str);
+ }
+ else
+ {
+ GdkColor color;
+
+ gdk_color_parse ("#E6D6B6", &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->calltip_back_color),
+ &color);
+ }
+
+ str = sci_prop_get (se->props, SELECTION_FORE_COLOR);
+ if(str)
+ {
+ GdkColor color;
+
+ gdk_color_parse (str, &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_fore_color),
+ &color);
+ g_free (str);
+ }
+ else
+ {
+ GdkColor color;
+
+ gdk_color_parse ("#FFFFFF", &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_fore_color),
+ &color);
+ }
+
+ str = sci_prop_get (se->props, SELECTION_BACK_COLOR);
+ if(str)
+ {
+ GdkColor color;
+
+ gdk_color_parse (str, &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_back_color),
+ &color);
+ g_free (str);
+ }
+ else
+ {
+ GdkColor color;
+
+ gdk_color_parse ("#000000", &color);
+ gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_back_color),
+ &color);
+ }
+}
+
+static void
+set_one_color (PropsID props, gchar *key, GtkWidget *picker)
+{
+ GdkColor color;
+ gchar *str;
+ gtk_color_button_get_color (GTK_COLOR_BUTTON (picker), &color);
+ str = anjuta_util_string_from_color (color.red,
+ color.green,
+ color.blue);
+ if(str)
+ {
+ sci_prop_set_with_key (props, key, str);
+ g_free (str);
+ }
+}
+
+static void
+sync_to_props (StyleEditor *se)
+{
+ gint i;
+ gchar *str;
+
+ g_return_if_fail (se);
+
+ /* Transfer to props */
+ for (i = 0;; i += 2)
+ {
+ StyleData *sdata;
+
+ if (hilite_style[i] == NULL)
+ break;
+ sdata =
+ g_object_get_data (G_OBJECT (se->priv->dialog),
+ hilite_style[i]);
+ str = style_data_get_string (sdata);
+ if (str)
+ {
+ sci_prop_set_with_key (se->props, hilite_style[i + 1], str);
+ g_free (str);
+ }
+ }
+ set_one_color (se->props, CARET_FORE_COLOR,
+ se->priv->caret_fore_color);
+
+ set_one_color (se->props, CALLTIP_BACK_COLOR,
+ se->priv->calltip_back_color);
+
+ set_one_color (se->props, SELECTION_FORE_COLOR,
+ se->priv->selection_fore_color);
+
+ set_one_color (se->props, SELECTION_BACK_COLOR,
+ se->priv->selection_back_color);
+}
+
/* Select a new style, update all entries */
static void
on_hilite_style_item_changed (StyleEditor *se)
@@ -548,6 +717,9 @@ on_font_changed (StyleEditor *se)
/* Changing bold and italic attribute could need a change in font */
on_hilite_style_item_changed (se);
+
+ sync_to_props (se);
+ g_signal_emit_by_name (se->plugin, "style-changed");
}
}
@@ -628,16 +800,19 @@ on_hilite_style_entry_changed (StyleEditor *se)
/* Changing bold and italic attribute could need a change in font */
on_hilite_style_item_changed (se);
+
+ sync_to_props (se);
+ g_signal_emit_by_name (se->plugin, "style-changed");
}
static void
-sync_from_props (StyleEditor *se)
+save_props (StyleEditor *se)
{
gint i;
gchar *str;
g_return_if_fail (se);
- /* Never hurts to use g_object_*_data as temp hash buffer */
+
for (i = 0;; i += 2)
{
StyleData *sdata;
@@ -645,152 +820,58 @@ sync_from_props (StyleEditor *se)
if (hilite_style[i] == NULL)
break;
str = sci_prop_get_expanded (se->props, hilite_style[i + 1]);
- sdata = style_data_new_parse (str);
- /* DEBUG_PRINT ("Parsing %s => %s", hilite_style[i + 1], str); */
- if (str)
- g_free (str);
-
- style_data_set_item (sdata, hilite_style[i]);
- g_object_set_data_full (G_OBJECT (se->priv->dialog),
- hilite_style[i], sdata,
- (GDestroyNotify)style_data_destroy);
+ se->priv->saved_props = g_list_prepend (se->priv->saved_props, str);
}
- se->priv->default_style =
- g_object_get_data (G_OBJECT (se->priv->dialog),
- hilite_style[0]);
- se->priv->current_style = NULL;
-
- on_hilite_style_item_changed (se);
str = sci_prop_get (se->props, CARET_FORE_COLOR);
- if(str)
- {
- GdkColor color;
-
- gdk_color_parse (str, &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->caret_fore_color),
- &color);
- g_free (str);
- }
- else
- {
- GdkColor color;
-
- gdk_color_parse ("#000000", &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->caret_fore_color),
- &color);
- }
-
+ se->priv->saved_props = g_list_prepend (se->priv->saved_props, str);
str = sci_prop_get (se->props, CALLTIP_BACK_COLOR);
- if(str)
- {
- GdkColor color;
-
- gdk_color_parse (str, &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->calltip_back_color),
- &color);
- g_free (str);
- }
- else
- {
- GdkColor color;
-
- gdk_color_parse ("#E6D6B6", &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->calltip_back_color),
- &color);
- }
-
+ se->priv->saved_props = g_list_prepend (se->priv->saved_props, str);
str = sci_prop_get (se->props, SELECTION_FORE_COLOR);
- if(str)
- {
- GdkColor color;
-
- gdk_color_parse (str, &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_fore_color),
- &color);
- g_free (str);
- }
- else
- {
- GdkColor color;
-
- gdk_color_parse ("#FFFFFF", &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_fore_color),
- &color);
- }
-
+ se->priv->saved_props = g_list_prepend (se->priv->saved_props, str);
str = sci_prop_get (se->props, SELECTION_BACK_COLOR);
- if(str)
- {
- GdkColor color;
-
- gdk_color_parse (str, &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_back_color),
- &color);
- g_free (str);
- }
- else
- {
- GdkColor color;
-
- gdk_color_parse ("#000000", &color);
- gtk_color_button_set_color (GTK_COLOR_BUTTON (se->priv->selection_back_color),
- &color);
- }
-}
+ se->priv->saved_props = g_list_prepend (se->priv->saved_props, str);
-static void
-set_one_color (PropsID props, gchar *key, GtkWidget *picker)
-{
- GdkColor color;
- gchar *str;
- gtk_color_button_get_color (GTK_COLOR_BUTTON (picker), &color);
- str = anjuta_util_string_from_color (color.red,
- color.green,
- color.blue);
- if(str)
- {
- sci_prop_set_with_key (props, key, str);
- g_free (str);
- }
+ se->priv->saved_props = g_list_reverse (se->priv->saved_props);
}
-
+
static void
-sync_to_props (StyleEditor *se)
+restore_props (StyleEditor *se)
{
gint i;
- gchar *str;
-
+ GList *str;
+
g_return_if_fail (se);
/* Transfer to props */
+ str = g_list_first (se->priv->saved_props);
for (i = 0;; i += 2)
{
StyleData *sdata;
if (hilite_style[i] == NULL)
break;
- sdata =
- g_object_get_data (G_OBJECT (se->priv->dialog),
- hilite_style[i]);
- str = style_data_get_string (sdata);
- if (str)
- {
- sci_prop_set_with_key (se->props, hilite_style[i + 1], str);
- g_free (str);
- }
+
+ if (str->data) sci_prop_set_with_key (se->props, hilite_style[i + 1], (gchar *)str->data);
+ str = g_list_next (str);
}
- set_one_color (se->props, CARET_FORE_COLOR,
- se->priv->caret_fore_color);
-
- set_one_color (se->props, CALLTIP_BACK_COLOR,
- se->priv->calltip_back_color);
-
- set_one_color (se->props, SELECTION_FORE_COLOR,
- se->priv->selection_fore_color);
-
- set_one_color (se->props, SELECTION_BACK_COLOR,
- se->priv->selection_back_color);
+ sci_prop_set_with_key (se->props, CARET_FORE_COLOR, (gchar *)str->data);
+ str = g_list_next (str);
+ sci_prop_set_with_key (se->props, CALLTIP_BACK_COLOR, (gchar *)str->data);
+ str = g_list_next (str);
+ sci_prop_set_with_key (se->props, SELECTION_FORE_COLOR, (gchar *)str->data);
+ str = g_list_next (str);
+ sci_prop_set_with_key (se->props, SELECTION_BACK_COLOR, (gchar *)str->data);
+}
+
+static void
+free_saved_props (StyleEditor *se)
+{
+ g_return_if_fail (se);
+
+ g_list_foreach (se->priv->saved_props, (GFunc)g_free, NULL);
+ g_list_free (se->priv->saved_props);
+ se->priv->saved_props = NULL;
}
static void
@@ -799,7 +880,6 @@ apply_styles (StyleEditor *se)
FILE *ofile;
gchar *filename;
- sync_to_props (se);
filename = anjuta_util_get_user_config_file_path ("scintilla","editor-style.properties",NULL);
ofile = fopen (filename, "w");
if (!ofile) {
@@ -809,6 +889,16 @@ apply_styles (StyleEditor *se)
fclose (ofile);
g_free (filename);
}
+}
+
+
+static void
+cancel_styles (StyleEditor *se)
+{
+ FILE *ofile;
+ gchar *filename;
+
+ restore_props (se);
g_signal_emit_by_name (se->plugin, "style-changed");
}
@@ -819,15 +909,17 @@ on_response (GtkWidget *dialog, gint res, StyleEditor *se)
switch (res)
{
- case GTK_RESPONSE_APPLY:
- apply_styles (se);
- return;
case GTK_RESPONSE_OK:
apply_styles (se);
+ style_editor_hide (se);
+ break;
case GTK_RESPONSE_CANCEL:
+ cancel_styles (se);
style_editor_hide (se);
- return;
+ break;
}
+
+ return;
}
static void
@@ -943,6 +1035,7 @@ style_editor_new (AnjutaPlugin *plugin, AnjutaPreferences *prefs, GSettings *set
se->priv = g_new0 (StyleEditorPriv, 1);
se->props = text_editor_get_props ();
se->priv->dialog = NULL;
+ se->priv->saved_props = NULL;
se->prefs = prefs;
se->settings = g_object_ref (settings);
se->plugin = g_object_ref (plugin);
@@ -954,6 +1047,7 @@ void style_editor_destroy (StyleEditor *se)
g_return_if_fail (se);
if (se->priv->dialog)
gtk_widget_destroy (se->priv->dialog);
+ free_saved_props (se);
g_free (se->priv);
g_object_unref (se->settings);
g_object_unref (se->plugin);
@@ -967,6 +1061,8 @@ void style_editor_show (StyleEditor *se)
return;
create_style_editor_gui (se);
sync_from_props (se);
+ save_props (se);
+ on_hilite_style_item_changed (se);
}
void style_editor_hide (StyleEditor *se)
@@ -975,6 +1071,7 @@ void style_editor_hide (StyleEditor *se)
g_return_if_fail (se->priv->dialog);
gtk_widget_destroy (se->priv->dialog);
se->priv->dialog = NULL;
+ free_saved_props (se);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]