Removed custom language styles

This commit is contained in:
Jesse van den Kieboom 2005-11-19 13:08:08 +00:00
parent 53276e8a54
commit a2db89cead
1 changed files with 28 additions and 121 deletions

View File

@ -12,6 +12,7 @@
#include "../gm-options.h"
#include "../gm-color-table.h"
#include "../gm-app.h"
#include "gm-searchable.h"
#define GM_EDITOR_VIEW_GET_PRIVATE(object)( \
G_TYPE_INSTANCE_GET_PRIVATE((object), \
@ -35,8 +36,10 @@ enum {
};
static guint gm_editor_view_signals[NUM_SIGNALS] = {0};
static void gm_editor_view_searchable_iface_init(
GmSearchableInterface *iface);
G_DEFINE_TYPE(GmEditorView, gm_editor_view, GTK_TYPE_VBOX)
static GtkTextView *gm_editor_view_searchable_get_text_view(GmSearchable *sea);
void on_gm_editor_view_save_clicked(GtkToolButton *button,
GmEditorView *view);
@ -46,12 +49,29 @@ void on_gm_editor_view_close_clicked(GtkToolButton *button,
GmEditorView *view);
void on_gm_editor_view_editor_saved(GmEditor *editor, GmEditorView *view);
void on_gm_editor_view_app_option_changed(GmOptions *options, gchar const *key);
void on_gm_editor_view_font_changed(GmColorTable *color_table,
gchar const *desc, GmEditorView *view);
void on_gm_editor_view_modified_changed(GtkTextBuffer *buffer,
GmEditorView *view);
G_DEFINE_TYPE_EXTENDED(GmEditorView, gm_editor_view, GTK_TYPE_VBOX, 0, \
G_IMPLEMENT_INTERFACE(GM_TYPE_SEARCHABLE, \
gm_editor_view_searchable_iface_init))
static void
gm_editor_view_searchable_iface_init(GmSearchableInterface *iface) {
iface->get_text_view = gm_editor_view_searchable_get_text_view;
}
static GtkTextView *
gm_editor_view_searchable_get_text_view(GmSearchable *sea) {
GmEditorView *view = (GmEditorView *)(sea);
g_return_val_if_fail(GM_IS_EDITOR_VIEW(sea), NULL);
return GTK_TEXT_VIEW(view->priv->source_view);
}
static void
gm_editor_view_finalize(GObject *object) {
//GmEditorView *obj = GM_EDITOR_VIEW(object);
@ -59,106 +79,13 @@ gm_editor_view_finalize(GObject *object) {
G_OBJECT_CLASS(gm_editor_view_parent_class)->finalize(object);
}
GtkSourceTag *
gm_editor_view_find_tag(gchar const *name) {
GSList *tags, *tag;
gchar *tname;
GtkSourceTag *st;
tags = gtk_source_language_get_tags(language);
for (tag = tags; tag; tag = tag->next) {
st = GTK_SOURCE_TAG(tag->data);
g_object_get(G_OBJECT(st), "name", &tname, NULL);
if (strcmp(name, tname) == 0) {
g_slist_free(tags);
g_free(tname);
return st;
}
g_free(tname);
}
g_slist_free(tags);
return NULL;
}
void
gm_editor_view_update_tag(GtkSourceTag *tag, gchar const *name,
gchar const *value) {
gchar **style;
GtkSourceTagStyle *sty;
gchar *id;
if (tag == NULL) {
tag = gm_editor_view_find_tag(name);
gm_editor_view_init_language() {
if (language_manager == NULL) {
language_manager = gtk_source_languages_manager_new();
language = gtk_source_languages_manager_get_language_from_mime_type(
language_manager, "text/x-moo");
}
if (tag == NULL) {
return;
}
g_object_get(G_OBJECT(tag), "id", &id, NULL);
sty = gtk_source_tag_get_style(tag);
style = g_strsplit(value, ",", 6);
if (g_strv_length(style) == 6) {
/* Foreground color */
if (strcmp(style[0], "0") == 0) {
sty->mask = sty->mask &
~GTK_SOURCE_TAG_STYLE_USE_FOREGROUND;
} else {
sty->mask = sty->mask | GTK_SOURCE_TAG_STYLE_USE_FOREGROUND;
gdk_color_parse(style[0], &(sty->foreground));
}
/* Background color */
if (strcmp(style[1], "0") == 0) {
sty->mask = sty->mask &
~GTK_SOURCE_TAG_STYLE_USE_BACKGROUND;
} else {
sty->mask = sty->mask | GTK_SOURCE_TAG_STYLE_USE_BACKGROUND;
gdk_color_parse(style[1], &(sty->background));
}
sty->bold = atoi(style[2]);
sty->italic = atoi(style[3]);
sty->underline = atoi(style[4]);
sty->strikethrough = atoi(style[5]);
gtk_source_language_set_tag_style(language, id, sty);
}
g_free(id);
g_strfreev(style);
}
static void
gm_editor_view_setup_tags() {
GmOptions *options = gm_app_options(gm_app_instance());
GSList *tags, *tag;
gchar *name, *oname;
gchar const *value;
GtkSourceTag *st;
tags = gtk_source_language_get_tags(language);
for (tag = tags; tag; tag = tag->next) {
st = GTK_SOURCE_TAG(tag->data);
g_object_get(G_OBJECT(st), "name", &name, NULL);
oname = g_strconcat("editor_", name, NULL);
if ((value = gm_options_get(options, oname))) {
gm_editor_view_update_tag(st, NULL, value);
}
g_free(oname);
g_free(name);
}
g_slist_free(tags);
}
static void
@ -178,17 +105,7 @@ gm_editor_view_class_init(GmEditorViewClass *klass) {
1,
G_TYPE_BOOLEAN);
if (language_manager == NULL) {
language_manager = gtk_source_languages_manager_new();
language = gtk_source_languages_manager_get_language_from_mime_type(
language_manager, "text/x-moo");
gm_editor_view_setup_tags();
g_signal_connect(gm_app_options(gm_app_instance()), "option_changed",
G_CALLBACK(on_gm_editor_view_app_option_changed), NULL);
}
gm_editor_view_init_language();
g_type_class_add_private(object_class, sizeof(GmEditorViewPrivate));
}
@ -379,16 +296,6 @@ on_gm_editor_view_close_clicked(GtkToolButton *button,
gm_editor_close(view->priv->editor);
}
void
on_gm_editor_view_app_option_changed(GmOptions *options, gchar const *key) {
gchar const *value;
if (strncmp(key, "editor_", 7) == 0) {
value = gm_options_get(options, key);
gm_editor_view_update_tag(NULL, key + 7, value);
}
}
void
on_gm_editor_view_modified_changed(GtkTextBuffer *buffer,
GmEditorView *view) {