Commit 4a4b4966 authored by Johannes Schmid's avatar Johannes Schmid Committed by Johannes Schmid

Changed color functions and moved convert_color to anjuta-utils.h

2006-04-12  Johannes Schmid <jhs@cvs.gnome.org>

	* ROADMAP:
	* libanjuta/anjuta-preferences.c:
	* libanjuta/anjuta-utils.c:
	* libanjuta/anjuta-utils.h:
	* plugins/message-view/message-view.c:

	Changed color functions and moved convert_color to anjuta-utils.h

	* plugins/message-view/anjuta-message-manager-plugin.glade:
	GnomeColorPicker -> GtkColorButton (bug #309154)

	* plugins/sourceview/plugin.c:
	* plugins/sourceview/sourceview-prefs.c:
	* plugins/sourceview/sourceview.glade:
	Added color and font preferences

	* plugins/sourceview/sourceview-tags.c:
	Only show as much choices as configured in preferences
parent 70d39f1c
2006-04-12 Johannes Schmid <jhs@cvs.gnome.org>
* ROADMAP:
* libanjuta/anjuta-preferences.c:
* libanjuta/anjuta-utils.c:
* libanjuta/anjuta-utils.h:
* plugins/message-view/message-view.c:
Changed color functions and moved convert_color to anjuta-utils.h
* plugins/message-view/anjuta-message-manager-plugin.glade:
GnomeColorPicker -> GtkColorButton (bug #309154)
* plugins/sourceview/plugin.c:
* plugins/sourceview/sourceview-prefs.c:
* plugins/sourceview/sourceview.glade:
Added color and font preferences
* plugins/sourceview/sourceview-tags.c:
Only show as much choices as configured in preferences
2006-04-11 Johannes Schmid <jhs@cvs.gnome.org>
* ROADMAP: Updated (we are far behind ;-)
* ROADMAP, NEWS: Updated (we are far behind ;-)
* plugins/document-manager/plugin.c: Hide Folding menu items if not supported
2006-04-11 Johannes Schmid <jhs@cvs.gnome.org>
......
......@@ -30,6 +30,7 @@ Milestone 2.0.2 - (Estimated release time April 2006)
Milestone 2.1.0 - (Estimated release time Oct 2006):
- Complete Users manual, tutorials and FAQ
- Include new debugger from anjuta-new-debugger branch
- Fix GDL to restore widgets dock locations correctly.
- Fix GDL to restore widgets geometry correctly on dock.
- Complete glade plugin integration
......
......@@ -25,12 +25,9 @@
#include <unistd.h>
#include <string.h>
#include <libgnomeui/gnome-color-picker.h>
#include <glade/glade-parser.h>
#include <gconf/gconf-client.h>
// #include <style-editor.h>
#include <libanjuta/anjuta-preferences.h>
#include <libanjuta/anjuta-utils.h>
#include <libanjuta/resources.h>
......@@ -196,16 +193,16 @@ get_property_value_as_string (AnjutaProperty *prop)
}
case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR:
{
guint8 r, g, b, a;
gnome_color_picker_get_i8 (GNOME_COLOR_PICKER (prop->object),
&r, &g, &b, &a);
text_value = anjuta_util_string_from_color (r, g, b);
GdkColor color;
gtk_color_button_get_color(GTK_COLOR_BUTTON (prop->object),
&color);
text_value = anjuta_util_string_from_color (color.red, color.green, color.blue);
}
break;
case ANJUTA_PROPERTY_OBJECT_TYPE_FONT:
{
const gchar *font;
font = gnome_font_picker_get_font_name (GNOME_FONT_PICKER
font = gtk_font_button_get_font_name (GTK_FONT_BUTTON
(prop->object));
text_value = g_strdup (font);
}
......@@ -305,15 +302,12 @@ set_property_value_as_string (AnjutaProperty *prop, const gchar *value)
case ANJUTA_PROPERTY_OBJECT_TYPE_COLOR:
{
guint8 r, g, b;
GdkColor color;
if (value)
anjuta_util_color_from_string (value, &r, &g, &b);
else
r = g = b = 0;
gnome_color_picker_set_i8 (GNOME_COLOR_PICKER (prop->object),
r, g, b, 8);
anjuta_util_color_from_string (value, &color.red, &color.green, &color.blue);
gtk_color_button_set_color(GTK_COLOR_BUTTON(prop->object), &color);
}
break;
......@@ -339,13 +333,13 @@ set_property_value_as_string (AnjutaProperty *prop, const gchar *value)
DEBUG_PRINT ("Font set as: %s", font_name);
gnome_font_picker_set_font_name (GNOME_FONT_PICKER
gtk_font_button_set_font_name (GTK_FONT_BUTTON
(prop->object), font_name);
g_free (font_name);
}
else
{
gnome_font_picker_set_font_name (GNOME_FONT_PICKER
gtk_font_button_set_font_name (GTK_FONT_BUTTON
(prop->object), value);
}
}
......@@ -435,8 +429,7 @@ update_property_on_change_int (GtkWidget *widget, gpointer user_data)
}
static void
update_property_on_change_color (GtkWidget *widget, guint arg1, guint arg2,
guint arg3, guint arg4, gpointer user_data)
update_property_on_change_color (GtkWidget *widget, gpointer user_data)
{
AnjutaPreferences *pr;
AnjutaProperty *p;
......@@ -451,7 +444,7 @@ update_property_on_change_color (GtkWidget *widget, guint arg1, guint arg2,
}
static void
update_property_on_change_font (GtkWidget *widget, guint arg1,
update_property_on_change_font (GtkWidget *widget,
gpointer user_data)
{
AnjutaPreferences *pr;
......
......@@ -120,11 +120,15 @@ int_from_hex_digit (const gchar ch)
}
void
anjuta_util_color_from_string (const gchar * val, guint8 * r, guint8 * g, guint8 * b)
anjuta_util_color_from_string (const gchar * val, guint16 * r, guint16 * g, guint16 * b)
{
*r = int_from_hex_digit (val[1]) * 16 + int_from_hex_digit (val[2]);
*g = int_from_hex_digit (val[3]) * 16 + int_from_hex_digit (val[4]);
*b = int_from_hex_digit (val[5]) * 16 + int_from_hex_digit (val[6]);
GdkColor color;
if (gdk_color_parse(val, &color))
{
*r = color.red;
*g = color.green;
*b =color.blue;
}
}
gchar *
......@@ -143,6 +147,27 @@ anjuta_util_string_from_color (guint8 r, guint8 g, guint8 b)
return g_strdup (str);
}
/* Get a GdkColor from preferences. Free the color with gdk_color_free() */
GdkColor*
anjuta_util_convert_color(AnjutaPreferences* prefs, const gchar* pref_name)
{
guint16 r, g, b;
guint factor = ((guint16) -1) / ((guint8) -1);
gchar* color;
GdkColor* gdkcolor = g_new0(GdkColor, 1);
color = anjuta_preferences_get(prefs, pref_name);
if (color)
{
anjuta_util_color_from_string (color, &r, &g, &b);
gdkcolor->pixel = 0;
gdkcolor->red = r * factor;
gdkcolor->green = g * factor;
gdkcolor->blue = b * factor;
g_free(color);
}
return gdkcolor;
}
GtkWidget*
anjuta_util_button_new_with_stock_image (const gchar* text,
const gchar* stock_id)
......
......@@ -24,15 +24,19 @@
#include <gtk/gtk.h>
#include <sys/types.h>
#include <libanjuta/anjuta-preferences.h>
gboolean anjuta_util_copy_file (gchar * src, gchar * dest, gboolean show_error);
gboolean anjuta_util_diff(const gchar* uri, const gchar* text);
void anjuta_util_color_from_string (const gchar * val, guint8 * r,
guint8 * g, guint8 * b);
void anjuta_util_color_from_string (const gchar * val, guint16 * r,
guint16 * g, guint16 * b);
gchar* anjuta_util_string_from_color (guint8 r, guint8 g, guint8 b);
GdkColor* anjuta_util_convert_color(AnjutaPreferences* prefs, const gchar* pref_name);
GtkWidget* anjuta_util_button_new_with_stock_image (const gchar* text,
const gchar* stock_id);
......
......@@ -627,25 +627,6 @@
<property name="row_spacing">5</property>
<property name="column_spacing">5</property>
<child>
<widget class="GnomeColorPicker" id="preferences_color:color:#FF0000:0:messages.color.error">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="dither">True</property>
<property name="use_alpha">False</property>
<property name="title" translatable="yes">Pick a color</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="left_attach">5</property>
<property name="right_attach">6</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label144">
<property name="visible">True</property>
......@@ -702,25 +683,6 @@
</packing>
</child>
<child>
<widget class="GnomeColorPicker" id="preferences_color:color:#0000FF:0:messages.color.info">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="dither">True</property>
<property name="use_alpha">False</property>
<property name="title" translatable="yes">Pick a color</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label145">
<property name="visible">True</property>
......@@ -750,12 +712,27 @@
</child>
<child>
<widget class="GnomeColorPicker" id="preferences_color:color:#00FF00:0:messages.color.warning">
<widget class="GtkColorButton" id="preferences_color:color:#0000FF:0:messages.color.info">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="use_alpha">False</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="preferences_color:color:#00FF00:0:messages.color.warning">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="dither">True</property>
<property name="use_alpha">False</property>
<property name="title" translatable="yes">Pick a color</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
......@@ -767,6 +744,23 @@
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkColorButton" id="preferences_color:color:#00FF00:0:messages.color.error">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="use_alpha">False</property>
<property name="focus_on_click">True</property>
</widget>
<packing>
<property name="left_attach">5</property>
<property name="right_attach">6</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
</child>
......
......@@ -159,27 +159,6 @@ add_char(gchar** str, gchar c)
*str = buffer;
}
/* Get a GdkColor from preferences. Free the color with gdk_color_free() */
static GdkColor*
convert_color(AnjutaPreferences* prefs, const gchar* pref_name)
{
guint8 r, g, b;
guint factor = ((guint16) -1) / ((guint8) -1);
gchar* color;
GdkColor* gdkcolor = g_new0(GdkColor, 1);
color = anjuta_preferences_get(prefs, pref_name);
if (color)
{
anjuta_util_color_from_string (color, &r, &g, &b);
gdkcolor->pixel = 0;
gdkcolor->red = r * factor;
gdkcolor->green = g * factor;
gdkcolor->blue = b * factor;
g_free(color);
}
return gdkcolor;
}
static gchar*
escape_string (const gchar *str)
{
......@@ -900,7 +879,7 @@ pref_change_color (MessageView *mview, IAnjutaMessageViewType type,
GtkTreeIter iter;
gboolean success;
color = convert_color (mview->privat->prefs, color_pref_key);
color = anjuta_util_convert_color (mview->privat->prefs, color_pref_key);
store = GTK_LIST_STORE (gtk_tree_view_get_model
(GTK_TREE_VIEW (mview->privat->tree_view)));
success = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
......@@ -1048,15 +1027,15 @@ imessage_view_append (IAnjutaMessageView *message_view,
switch (message->type)
{
case IANJUTA_MESSAGE_VIEW_TYPE_INFO:
color = convert_color(view->privat->prefs,
color = anjuta_util_convert_color(view->privat->prefs,
"messages.color.info");
break;
case IANJUTA_MESSAGE_VIEW_TYPE_WARNING:
color = convert_color(view->privat->prefs,
color = anjuta_util_convert_color(view->privat->prefs,
"messages.color.warning");
break;
case IANJUTA_MESSAGE_VIEW_TYPE_ERROR:
color = convert_color(view->privat->prefs,
color = anjuta_util_convert_color(view->privat->prefs,
"messages.color.error");
break;
default:
......
......@@ -37,20 +37,62 @@
#define PREFS_GLADE PACKAGE_DATA_DIR"/glade/sourceview.glade"
#define ICON_FILE "sourceview.png"
#define COLOR_USE_THEME_BUTTON "preferences_toggle:bool:1:0:sourceview.color.use_theme"
#define COLOR_TEXT "preferences_color:color:#FFFFFF:0:sourceview.color.text"
#define COLOR_BACKGROUND "preferences_color:color:#000000:0:sourceview.color.background"
#define COLOR_SELECTED_TEXT "preferences_color:color:#000000:0:sourceview.color.selected_text"
#define COLOR_SELECTION "preferences_color:color:#0000FF:0:sourceview.color.selection"
#define FONT_USE_THEME_BUTTON "preferences_toggle:bool:1:0:sourceview.font.use_theme"
#define FONT_BUTTON "preferences_font:font:Sans:0:sourceview.font"
static gpointer parent_class;
static void
on_color_check_toggled(GtkToggleButton* button, GladeXML* gxml)
{
GtkWidget* color_button;
color_button = glade_xml_get_widget(gxml, COLOR_TEXT);
gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
color_button = glade_xml_get_widget(gxml, COLOR_BACKGROUND);
gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
color_button = glade_xml_get_widget(gxml, COLOR_SELECTED_TEXT);
gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
color_button = glade_xml_get_widget(gxml, COLOR_SELECTION);
gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
}
static void
on_font_check_toggled(GtkToggleButton* button, GladeXML* gxml)
{
GtkWidget* font_button;
font_button = glade_xml_get_widget(gxml, FONT_BUTTON);
gtk_widget_set_sensitive(font_button, !gtk_toggle_button_get_active(button));
}
static gboolean
sourceview_plugin_activate (AnjutaPlugin *plugin)
{
/* Add preferences */
AnjutaPreferences* prefs;
AnjutaShell* shell;
GtkWidget* check_color;
GtkWidget* check_font;
GladeXML* gxml;
g_object_get(G_OBJECT(plugin), "shell", &shell, NULL);
prefs = anjuta_shell_get_preferences(shell, NULL);
gxml = glade_xml_new (PREFS_GLADE, "preferences_dialog", NULL);
anjuta_preferences_add_page (prefs,
gxml, "Editor", ICON_FILE);
check_color = glade_xml_get_widget(gxml, COLOR_USE_THEME_BUTTON);
g_signal_connect(G_OBJECT(check_color), "toggled", G_CALLBACK(on_color_check_toggled), gxml);
check_font = glade_xml_get_widget(gxml, FONT_USE_THEME_BUTTON);
g_signal_connect(G_OBJECT(check_font), "toggled", G_CALLBACK(on_font_check_toggled), gxml);
DEBUG_PRINT ("SourceviewPlugin: Activating SourceviewPlugin plugin ...");
return TRUE;
......
......@@ -37,6 +37,15 @@ static AnjutaPreferences* prefs = NULL;
#define VIEW_LINENUMBERS_MARGIN "margin.linenumber.visible"
#define VIEW_MARKER_MARGIN "margin.marker.visible"
#define COLOR_THEME "sourceview.color.use_theme"
#define COLOR_TEXT "sourceview.color.text"
#define COLOR_BACKGROUND "sourceview.color.background"
#define COLOR_SELECTED_TEXT "sourceview.color.selected_text"
#define COLOR_SELECTION "sourceview.color.selection"
#define FONT_THEME "sourceview.font.use_theme"
#define FONT "sourceview.font"
static int
get_int(GConfEntry* entry)
{
......@@ -149,6 +158,69 @@ on_gconf_notify_view_linenums (GConfClient *gclient, guint cnxn_id,
}
static void
on_gconf_notify_color (GConfClient *gclient, guint cnxn_id,
GConfEntry *entry, gpointer user_data)
{
Sourceview *sv;
GdkColor *text, *background, *selected_text, *selection;
AnjutaPreferences* prefs = sourceview_get_prefs();
sv = ANJUTA_SOURCEVIEW(user_data);
text = anjuta_util_convert_color(prefs, COLOR_TEXT);
background = anjuta_util_convert_color(prefs, COLOR_BACKGROUND);
selected_text = anjuta_util_convert_color(prefs, COLOR_SELECTED_TEXT);
selection = anjuta_util_convert_color(prefs, COLOR_SELECTION);
anjuta_view_set_colors(sv->priv->view, FALSE, background, text, selection, selected_text);
}
static void
on_gconf_notify_color_theme (GConfClient *gclient, guint cnxn_id,
GConfEntry *entry, gpointer user_data)
{
Sourceview *sv;
gboolean use_theme = get_bool(entry);
sv = ANJUTA_SOURCEVIEW(user_data);
if (use_theme)
{
anjuta_view_set_colors(sv->priv->view, TRUE, NULL, NULL, NULL, NULL);
}
else
on_gconf_notify_color(NULL, 0, NULL, sv);
}
static void
on_gconf_notify_font (GConfClient *gclient, guint cnxn_id,
GConfEntry *entry, gpointer user_data)
{
Sourceview *sv;
gchar* font;
AnjutaPreferences* prefs = sourceview_get_prefs();
sv = ANJUTA_SOURCEVIEW(user_data);
font = anjuta_preferences_get(prefs, FONT);
anjuta_view_set_font(sv->priv->view, FALSE, font);
}
static void
on_gconf_notify_font_theme (GConfClient *gclient, guint cnxn_id,
GConfEntry *entry, gpointer user_data)
{
Sourceview *sv;
gboolean use_theme = get_bool(entry);
sv = ANJUTA_SOURCEVIEW(user_data);
if (use_theme)
{
anjuta_view_set_font(sv->priv->view, TRUE, NULL);
}
else
on_gconf_notify_font(NULL, 0, NULL, sv);
}
static int
get_key(Sourceview* sv, const gchar* key)
{
......@@ -185,6 +257,14 @@ sourceview_prefs_init(Sourceview* sv)
REGISTER_NOTIFY (BACKSPACE_UNINDENTS, on_gconf_notify_backspace_unindents);
REGISTER_NOTIFY (VIEW_MARKER_MARGIN, on_gconf_notify_view_markers);
REGISTER_NOTIFY (VIEW_LINENUMBERS_MARGIN, on_gconf_notify_view_linenums);
REGISTER_NOTIFY (COLOR_THEME, on_gconf_notify_color_theme);
REGISTER_NOTIFY (COLOR_TEXT, on_gconf_notify_color);
REGISTER_NOTIFY (COLOR_BACKGROUND, on_gconf_notify_color);
REGISTER_NOTIFY (COLOR_SELECTED_TEXT, on_gconf_notify_color);
REGISTER_NOTIFY (COLOR_SELECTION, on_gconf_notify_color);
REGISTER_NOTIFY (FONT_THEME, on_gconf_notify_font_theme);
REGISTER_NOTIFY (FONT, on_gconf_notify_font);
}
AnjutaPreferences*
......
......@@ -56,6 +56,7 @@ enum
N_COLUMNS
};
#define AUTOCOMPLETE_CHOICES "autocompleteword.choices"
static gboolean
sourceview_tags_update(TagWindow* tagwin, GtkWidget* view)
{
......@@ -101,7 +102,9 @@ sourceview_tags_update(TagWindow* tagwin, GtkWidget* view)
current_word,
TRUE, TRUE, NULL);
if (!ianjuta_iterable_get_length(tags, NULL))
if (!ianjuta_iterable_get_length(tags, NULL) ||
ianjuta_iterable_get_length(tags, NULL) >
anjuta_preferences_get_int (sourceview_get_prefs(), AUTOCOMPLETE_CHOICES))
{
return FALSE;
g_object_unref(tags);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment