[anjuta-extras] scintilla: Improve indicators
- From: Sebastien Granjoux <sgranjoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta-extras] scintilla: Improve indicators
- Date: Sat, 17 Sep 2011 18:41:15 +0000 (UTC)
commit aa637564689ba5a01dff3475fb13cc78b52045cb
Author: SÃbastien Granjoux <seb sfo free fr>
Date: Sat Sep 17 19:45:41 2011 +0200
scintilla: Improve indicators
plugins/scintilla/aneditor.cxx | 31 ++++-
plugins/scintilla/properties/anjuta.properties | 16 ++-
plugins/scintilla/text_editor.c | 173 +++++++++++++-----------
plugins/scintilla/text_editor.h | 5 +
4 files changed, 135 insertions(+), 90 deletions(-)
---
diff --git a/plugins/scintilla/aneditor.cxx b/plugins/scintilla/aneditor.cxx
index 3019ee1..5941b61 100644
--- a/plugins/scintilla/aneditor.cxx
+++ b/plugins/scintilla/aneditor.cxx
@@ -2641,9 +2641,8 @@ void AnEditor::ReadProperties(const char *fileForExt, char **typedef_hl) {
SString value_str;
long default_indic_type[] = {INDIC_TT, INDIC_DIAGONAL, INDIC_SQUIGGLE};
const char *default_indic_color[] = {"0000FF", "#00FF00", "#FF0000"};
- const char *style_name[] = {"normal", "warning", "error"};
char key[200];
- sprintf(key, "indicators.style.%s", style_name[i]);
+ sprintf(key, "indicator.%d.style", i);
value_str = props->Get(key);
if (value_str.length() > 0) {
@@ -2657,6 +2656,22 @@ void AnEditor::ReadProperties(const char *fileForExt, char **typedef_hl) {
SendEditor(SCI_INDICSETSTYLE, i, INDIC_STRIKE);
} else if (strcasecmp (value_str.c_str(), "diagonal") == 0) {
SendEditor(SCI_INDICSETSTYLE, i, INDIC_DIAGONAL);
+ } else if (strcasecmp (value_str.c_str(), "hidden") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_HIDDEN);
+ } else if (strcasecmp (value_str.c_str(), "box") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_BOX);
+ } else if (strcasecmp (value_str.c_str(), "roundbox") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_ROUNDBOX);
+ } else if (strcasecmp (value_str.c_str(), "straightbox") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_STRAIGHTBOX);
+ } else if (strcasecmp (value_str.c_str(), "underline-dash") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_DASH);
+ } else if (strcasecmp (value_str.c_str(), "underline-dots") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_DOTS);
+ } else if (strcasecmp (value_str.c_str(), "underline-low-squiggle") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_SQUIGGLELOW);
+ } else if (strcasecmp (value_str.c_str(), "dotbox") == 0) {
+ SendEditor(SCI_INDICSETSTYLE, i, INDIC_DOTBOX);
} else {
SendEditor(SCI_INDICSETSTYLE, i, default_indic_type[i]);
}
@@ -2670,6 +2685,18 @@ void AnEditor::ReadProperties(const char *fileForExt, char **typedef_hl) {
} else {
SendEditor(SCI_INDICSETFORE, i, ColourFromString(default_indic_color[i]).AsLong());
}
+
+ sprintf(key, "indicator.%d.under", i);
+ value_str = props->GetExpanded(key);
+ if (value_str.length()) {
+ SendEditor(SCI_INDICSETUNDER, i, props->GetInt(key));
+ }
+
+ sprintf(key, "indicator.%d.alpha", i);
+ value_str = props->GetExpanded(key);
+ if (value_str.length()) {
+ SendEditor(SCI_INDICSETALPHA, i, props->GetInt(key));
+ }
}
char bracesStyleKey[200];
diff --git a/plugins/scintilla/properties/anjuta.properties b/plugins/scintilla/properties/anjuta.properties
index a80938a..9bb1e2d 100644
--- a/plugins/scintilla/properties/anjuta.properties
+++ b/plugins/scintilla/properties/anjuta.properties
@@ -395,16 +395,19 @@ indicators.automatic=1
## INDIC_STRIKE => Strike-Out
# General indicator
-indicator.0.style=Underline-TT
-indicator.0.color=$(messages.color.messages1)
+indicator.0.style=StraightBox
+indicator.0.color=$(messages.color.important)
+indicator.0.alpha=255
+indicator.0.under=1
# Warning indicator
indicator.1.style=Underline-Squiggle
-indicator.1.color=$(messages.color.warning)
+# Color is overwritten by message manager setting
# Errors indicator
-indicator.2.style=Strike-Out
-indicator.2.color=$(messages.color.error)
+indicator.2.style=Strike-out
+# Color is overwritten by message manager setting
+indicator.2.color=$(messages.color.important)
# Blank margin width on the left of the editor (in text space)
# units in pixels
@@ -492,8 +495,7 @@ caret.fore=#000000
# Messages colors
messages.color.warning=#00FF00
messages.color.error=#FF0000
-messages.color.messages1=#0000FF
-messages.color.messages2=#000000
+messages.color.important=#FFFF00
# Messages notebook tag position (Top, Bottom, Left, Right).
messages.tag.position=Bottom
diff --git a/plugins/scintilla/text_editor.c b/plugins/scintilla/text_editor.c
index 02340c9..62f0c6a 100644
--- a/plugins/scintilla/text_editor.c
+++ b/plugins/scintilla/text_editor.c
@@ -116,6 +116,7 @@ static void text_editor_hilite_one (TextEditor * te, AnEditorID editor);
static GtkVBoxClass *parent_class;
+
static void
text_editor_instance_init (TextEditor *te)
{
@@ -146,6 +147,7 @@ text_editor_instance_init (TextEditor *te)
te->settings = g_settings_new (PREF_SCHEMA);
te->docman_settings = g_settings_new (DOCMAN_PREF_SCHEMA);
+ te->msgman_settings = g_settings_new (MSGMAN_PREF_SCHEMA);
}
static GtkWidget *
@@ -228,6 +230,35 @@ on_te_already_destroyed (gpointer te, GObject *obj)
}
#endif
+/* Indicators are setup in both TextEditor and AnEditor object.
+ * AnEditor reads the property file while TexEditor uses the
+ * GSettings object. TextEditor can overwrite properties
+ * set by AnEditor.
+ */
+static void
+text_editor_setup_indicators_color (TextEditor *te)
+{
+ char* spec;
+ GdkColor color;
+
+ /* Warning color */
+ spec = g_settings_get_string (te->msgman_settings, MSGMAN_COLOR_WARNING);
+ if (gdk_color_parse (spec, &color))
+ {
+ glong param = ((color.red >> 8) & 0xFF) + (color.green & 0xFF00) + ((color.blue << 8) & 0x00FF0000);
+ scintilla_send_message (SCINTILLA (te->scintilla), SCI_INDICSETFORE, 1, param);
+ }
+ g_free (spec);
+ /* Error color */
+ spec = g_settings_get_string (te->msgman_settings, MSGMAN_COLOR_ERROR);
+ if (gdk_color_parse (spec, &color))
+ {
+ glong param = ((color.red >> 8) & 0xFF) + (color.green & 0xFF00) + ((color.blue << 8) & 0x00FF0000);
+ scintilla_send_message (SCINTILLA (te->scintilla), SCI_INDICSETFORE, 2, param);
+ }
+ g_free (spec);
+}
+
void
text_editor_add_view (TextEditor *te)
{
@@ -559,6 +590,13 @@ on_style_changed (TextEditor *te)
text_editor_hilite (te, te->force_pref);
}
+static void
+on_indicators_changed (TextEditor *te)
+{
+ /* Refresh indicator */
+ text_editor_setup_indicators_color (te);
+}
+
GtkWidget *
text_editor_new (AnjutaPlugin *plugin, const gchar *uri, const gchar *name)
{
@@ -612,12 +650,14 @@ text_editor_new (AnjutaPlugin *plugin, const gchar *uri, const gchar *name)
zoom_factor = g_settings_get_int (te->docman_settings, TEXT_ZOOM_FACTOR);
/* DEBUG_PRINT ("%s", "Initializing zoom factor to: %d", zoom_factor); */
text_editor_set_zoom_factor (te, zoom_factor);
-
+ text_editor_setup_indicators_color (te);
+
/* Get type name notification */
g_signal_connect_swapped (G_OBJECT (shell), "value-added", G_CALLBACK (on_shell_value_changed), te);
g_signal_connect_swapped (G_OBJECT (shell), "value-removed", G_CALLBACK (on_shell_value_changed), te);
g_signal_connect_swapped (G_OBJECT (plugin), "style-changed", G_CALLBACK(on_style_changed), te);
-
+
+ g_signal_connect_swapped (G_OBJECT(te->msgman_settings), "changed", G_CALLBACK (on_indicators_changed), te);
#ifdef DEBUG
g_object_weak_ref (G_OBJECT (te), on_te_already_destroyed, te);
@@ -692,6 +732,7 @@ text_editor_dispose (GObject *obj)
te->completion_count = 0;
g_object_unref (te->settings);
g_object_unref (te->docman_settings);
+ g_object_unref (te->msgman_settings);
G_OBJECT_CLASS (parent_class)->dispose (obj);
}
@@ -802,6 +843,8 @@ text_editor_hilite (TextEditor * te, gboolean override_by_pref)
text_editor_hilite_one (te, GPOINTER_TO_INT (node->data));
node = g_list_next (node);
}
+
+ text_editor_setup_indicators_color (te);
}
void
@@ -1119,88 +1162,56 @@ gint
text_editor_set_indicator (TextEditor *te, gint start,
gint end, gint indicator)
{
- gchar ch;
- glong indic_mask[] = {INDIC0_MASK, INDIC1_MASK, INDIC2_MASK};
- gint current_styling_pos;
+ g_return_val_if_fail (te != NULL, -1);
+ g_return_val_if_fail (IS_SCINTILLA (te->scintilla) == TRUE, -1);
+
+ scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_SETINDICATORCURRENT, indicator, 0);
+ scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_INDICATORFILLRANGE, start, end - start);
+
+ return 0;
+}
+
+static gint
+text_editor_clear_indicator (TextEditor *te, gint start,
+ gint end)
+{
+ gint i;
g_return_val_if_fail (te != NULL, -1);
g_return_val_if_fail (IS_SCINTILLA (te->scintilla) == TRUE, -1);
- if (start >= 0) {
- end --; /* supplied end-location is one-past the last char to process */
- if (end < start)
- return -1;
+ for (i = 0; i < 3; i++)
+ {
+ scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_SETINDICATORCURRENT, i, 0);
+ scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_INDICATORCLEARRANGE, start, end - start);
+ }
- do
- {
- ch = scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETCHARAT, start, 0);
- start++;
- } while (isspace(ch));
- start--;
-
- do {
- ch = scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETCHARAT, end, 0);
- end--;
- } while (isspace(ch));
- end++;
- if (end < start) return -1;
-
- current_styling_pos = scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETENDSTYLED, 0, 0);
- if (indicator >= 0 && indicator < 3) {
- char current_mask;
- current_mask =
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETSTYLEAT, start, 0);
- current_mask &= INDICS_MASK;
- current_mask |= indic_mask[indicator];
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_STARTSTYLING, start, INDICS_MASK);
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_SETSTYLING, end-start+1, current_mask);
- } else {
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_STARTSTYLING, start, INDICS_MASK);
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_SETSTYLING, end-start+1, 0);
- }
- if (current_styling_pos < start)
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_STARTSTYLING, current_styling_pos,
- 0x1F);
- } else {
- if (indicator < 0) {
- char current_mask;
- glong i, last, start_style_pos = 0;
-
- last = scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETTEXTLENGTH, 0, 0);
- current_styling_pos = scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETENDSTYLED, 0, 0);
- for (i = 0; i < last; i++)
- {
- current_mask =
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_GETSTYLEAT, i, 0);
- current_mask &= INDICS_MASK;
- if (current_mask != 0)
- {
- if (start_style_pos == 0)
- start_style_pos = i;
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_STARTSTYLING, i, INDICS_MASK);
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_SETSTYLING, 1, 0);
- }
- }
- if (current_styling_pos < start_style_pos)
- scintilla_send_message (SCINTILLA (te->scintilla),
- SCI_STARTSTYLING, current_styling_pos,
- 0x1F);
- }
+ return 0;
+}
+
+static gint
+text_editor_clear_all_indicator (TextEditor *te)
+{
+ glong last;
+ gint i;
+
+ g_return_val_if_fail (te != NULL, -1);
+ g_return_val_if_fail (IS_SCINTILLA (te->scintilla) == TRUE, -1);
+
+ last = scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_GETTEXTLENGTH, 0, 0);
+ for (i = 0; i < 3; i++)
+ {
+ scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_SETINDICATORCURRENT, i, 0);
+ scintilla_send_message (SCINTILLA (te->scintilla),
+ SCI_INDICATORCLEARRANGE, 0, last);
}
+
return 0;
}
@@ -3425,7 +3436,7 @@ iindicable_set (IAnjutaIndicable *te, IAnjutaIterable *begin_location,
switch (indicator)
{
case IANJUTA_INDICABLE_NONE:
- text_editor_set_indicator (TEXT_EDITOR (te), begin, end, -1);
+ text_editor_clear_indicator (TEXT_EDITOR (te), begin, end);
break;
case IANJUTA_INDICABLE_IMPORTANT:
text_editor_set_indicator (TEXT_EDITOR (te), begin, end, 0);
@@ -3438,7 +3449,7 @@ iindicable_set (IAnjutaIndicable *te, IAnjutaIterable *begin_location,
break;
default:
g_warning ("Unsupported indicator %d", indicator);
- text_editor_set_indicator (TEXT_EDITOR (te), begin, end, -1);
+ text_editor_clear_indicator (TEXT_EDITOR (te), begin, end);
break;
}
}
@@ -3446,7 +3457,7 @@ iindicable_set (IAnjutaIndicable *te, IAnjutaIterable *begin_location,
static void
iindicable_clear (IAnjutaIndicable *te, GError **err)
{
- text_editor_set_indicator (TEXT_EDITOR (te), -1, -1, -1);
+ text_editor_clear_all_indicator (TEXT_EDITOR (te));
}
static void
diff --git a/plugins/scintilla/text_editor.h b/plugins/scintilla/text_editor.h
index 98febb5..06dd05d 100644
--- a/plugins/scintilla/text_editor.h
+++ b/plugins/scintilla/text_editor.h
@@ -86,6 +86,7 @@ struct _TextEditor
/* Settings */
GSettings *settings;
GSettings *docman_settings;
+ GSettings *msgman_settings;
/* Editor ID and widget for AnEditor */
AnEditorID editor_id;
@@ -288,6 +289,10 @@ void text_editor_scintilla_command (TextEditor *te, gint command,
#define DOCMAN_PREF_SCHEMA "org.gnome.anjuta.document-manager"
#define TEXT_ZOOM_FACTOR "text-zoom-factor"
+#define MSGMAN_PREF_SCHEMA "org.gnome.anjuta.message-manager"
+#define MSGMAN_COLOR_ERROR "msgman-color-error"
+#define MSGMAN_COLOR_WARNING "msgman-color-warning"
+
#define PREF_SCHEMA "org.gnome.anjuta.scintilla"
/* Editor preferences */
#define DISABLE_SYNTAX_HILIGHTING "disable-syntax-hilighting"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]