anjuta r3681 - in trunk: . plugins/language-support-cpp-java plugins/sourceview
- From: jhs svn gnome org
- To: svn-commits-list gnome org
- Subject: anjuta r3681 - in trunk: . plugins/language-support-cpp-java plugins/sourceview
- Date: Sun, 17 Feb 2008 10:54:40 +0000 (GMT)
Author: jhs
Date: Sun Feb 17 10:54:40 2008
New Revision: 3681
URL: http://svn.gnome.org/viewvc/anjuta?rev=3681&view=rev
Log:
2008-02-17 Johannes Schmid <jhs gnome org>
* plugins/language-support-cpp-java/plugin.c:
(get_line_indentation_base), (get_line_auto_indentation),
(on_auto_indent):
Some bugfixes and clean-ups in comment indentation code
* plugins/sourceview/anjuta-view.c: (anjuta_view_class_init),
(anjuta_view_finalize), (anjuta_view_key_press_event):
* plugins/sourceview/sourceview.c: (on_insert_text),
(sourceview_create_highligth_indic), (sourceview_new):
Cleaned implementation of char-added signal by using \"insert-text\" signal
instead of filtering \"key-press-event\"
* plugins/sourceview/sourceview-cell.c: (icell_get_character),
(icell_get_length), (icell_get_char), (iiter_first), (iiter_last),
(iiter_diff):
Fixed implementation of get_character and return value of iiter_first() and
iiter_last();
Modified:
trunk/ChangeLog
trunk/plugins/language-support-cpp-java/plugin.c
trunk/plugins/sourceview/anjuta-view.c
trunk/plugins/sourceview/sourceview-cell.c
trunk/plugins/sourceview/sourceview.c
Modified: trunk/plugins/language-support-cpp-java/plugin.c
==============================================================================
--- trunk/plugins/language-support-cpp-java/plugin.c (original)
+++ trunk/plugins/language-support-cpp-java/plugin.c Sun Feb 17 10:54:40 2008
@@ -825,6 +825,7 @@
gboolean looking_at_just_next_line = TRUE;
gboolean current_line_is_preprocessor = FALSE;
gboolean current_line_is_continuation = FALSE;
+ gboolean line_checked_for_comment = FALSE;
*incomplete_statement = -1;
@@ -923,6 +924,7 @@
if (point_ch == '}' && get_line_indentation (editor, line_saved) <= 0)
{
line_indent = 0;
+ line_indent += extra_indent;
break;
}
@@ -1035,96 +1037,89 @@
*/
}
looking_at_just_next_line = FALSE;
+ line_checked_for_comment = FALSE;
}
else if (!isspace (point_ch))
{
/* Check for line starting comment */
- gboolean comment = FALSE;
- IAnjutaIterable* new_iter = ianjuta_iterable_clone (iter, NULL);
- do
+ if (!line_checked_for_comment)
{
- gchar c;
- c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (new_iter), 0,
- NULL);
- if (iter_is_newline (new_iter, c))
- break;
- if (c == '/')
+ gboolean comment = FALSE;
+ IAnjutaIterable* new_iter = ianjuta_iterable_clone (iter, NULL);
+ do
{
- ianjuta_iterable_previous (iter, NULL);
+ gchar c;
c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (new_iter), 0,
NULL);
- if (c == '/')
+ if (iter_is_newline (new_iter, c))
{
- /* is a line comment, skip until begin of comment */
- comment = TRUE;
+ line_checked_for_comment = TRUE;
break;
}
- }
- if (c == '*')
- {
- IAnjutaIterable* prev = ianjuta_iterable_clone (new_iter, NULL);
- ianjuta_iterable_previous (prev, NULL);
- c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (prev), 0,
- NULL);
if (c == '/')
{
- /* starts comment */
- comment = TRUE;
- extra_indent++;
- g_object_unref (prev);
- break;
- }
- /* Possibly continued comment */
- else if (isspace(c))
- {
- do
+ ianjuta_iterable_previous (new_iter, NULL);
+ c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (new_iter), 0,
+ NULL);
+ if (c == '/')
{
- ianjuta_iterable_previous (prev, NULL);
- c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (prev), 0,
- NULL);
- if (iter_is_newline (prev, c))
- {
- /* Add a space to ensure correct comment indentation */
- continue;
- }
+ /* is a line comment, skip until begin of comment */
+ comment = TRUE;
+ break;
}
- while (isspace(c));
- ianjuta_iterable_set_position (new_iter,
- ianjuta_iterable_get_position (prev, NULL),
- NULL);
- g_object_unref (prev);
- DEBUG_PRINT ("Continues comment");
- continue;
}
- else
+ if (c == '*')
{
- IAnjutaIterable* next = ianjuta_iterable_clone (new_iter, NULL);
- ianjuta_iterable_next (next, NULL);
-
- /* Could also be the end of a comment in which case we
- * will simply bail out
- */
- c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (next), 0, NULL);
+ IAnjutaIterable* prev = ianjuta_iterable_clone (new_iter, NULL);
+ ianjuta_iterable_previous (prev, NULL);
+ c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (prev), 0,
+ NULL);
if (c == '/')
{
- g_object_unref (next);
+ /* starts comment */
+ comment = TRUE;
+ extra_indent++;
+ g_object_unref (prev);
break;
}
- g_object_unref (next);
+ /* Possibly continued comment */
+ else if (isspace(c))
+ {
+ gboolean possible_comment = FALSE;
+ while (ianjuta_iterable_previous (prev, NULL))
+ {
+ c = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (prev), 0,
+ NULL);
+ if (!isspace(c))
+ break;
+ if (iter_is_newline (prev, c))
+ {
+ possible_comment = TRUE;
+ break;
+ }
+ }
+ if (possible_comment)
+ {
+ ianjuta_iterable_set_position (new_iter,
+ ianjuta_iterable_get_position (prev, NULL),
+ NULL);
+ g_object_unref (prev);
+ continue;
+ }
+ }
+ g_object_unref (prev);
}
+ } while (ianjuta_iterable_previous (new_iter, NULL));
+ if (comment)
+ {
+ ianjuta_iterable_set_position (iter,
+ ianjuta_iterable_get_position (new_iter, NULL) - 1,
+ NULL);
+ g_object_unref (new_iter);
+ continue;
}
- }
- while (ianjuta_iterable_previous (new_iter, NULL));
- if (comment)
- {
- DEBUG_PRINT ("Found comment");
- ianjuta_iterable_set_position (iter,
- ianjuta_iterable_get_position (new_iter, NULL) - 1,
- NULL);
g_object_unref (new_iter);
- continue;
}
- g_object_unref (new_iter);
/* If we encounter any non-whitespace char before any of the
* statement-complete indicators, the statement is basically
@@ -1134,6 +1129,8 @@
*incomplete_statement = 1;
}
}
+ if (ianjuta_iterable_first (iter, NULL))
+ line_indent += extra_indent;
g_object_unref (iter);
return line_indent;
@@ -1216,7 +1213,6 @@
{
ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (end_iter),
0, NULL);
- DEBUG_PRINT ("line-end: %c", ch);
if (ch == ':')
{
line_indent -= INDENT_SIZE;
@@ -1595,7 +1591,7 @@
{
line_indent = get_line_auto_indentation (lang_plugin, editor,
insert_line);
- DEBUG_PRINT ("Line indent for line %d = %d", insert_line, line_indent);
+ /* DEBUG_PRINT ("Line indent for line %d = %d", insert_line, line_indent); */
set_line_indentation (editor, insert_line, line_indent);
}
ianjuta_document_end_undo_action (IANJUTA_DOCUMENT(editor), NULL);
Modified: trunk/plugins/sourceview/anjuta-view.c
==============================================================================
--- trunk/plugins/sourceview/anjuta-view.c (original)
+++ trunk/plugins/sourceview/anjuta-view.c Sun Feb 17 10:54:40 2008
@@ -54,20 +54,6 @@
#define ANJUTA_VIEW_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), ANJUTA_TYPE_VIEW, AnjutaViewPrivate))
-enum {
- CHAR_ADDED,
- LAST_SIGNAL
-};
-
-static guint view_signals[LAST_SIGNAL] = { 0 };
-
-enum
-{
- TAG = 0,
- AUTOCOMPLETE,
- SCOPE,
-};
-
enum
{
ANJUTA_VIEW_POPUP = 1
@@ -75,7 +61,6 @@
struct _AnjutaViewPrivate
{
- GtkTooltips *tooltips;
GtkWidget* popup;
guint scroll_idle;
Sourceview* sv;
@@ -215,18 +200,6 @@
ANJUTA_VIEW_POPUP,
anjuta_view_spec_popup);
- view_signals[CHAR_ADDED] =
- g_signal_new ("char_added",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (AnjutaViewClass, char_added),
- NULL, NULL,
- anjuta_marshal_VOID__OBJECT_CHAR,
- G_TYPE_NONE,
- 2,
- G_TYPE_INT,
- G_TYPE_CHAR);
-
binding_set = gtk_binding_set_by_class (klass);
}
@@ -363,9 +336,6 @@
AnjutaView *view;
view = ANJUTA_VIEW (object);
-
- if (view->priv->tooltips != NULL)
- g_object_unref (view->priv->tooltips);
if (view->priv->popup != NULL)
{
@@ -758,15 +728,11 @@
{
GtkTextBuffer *buffer;
AnjutaView* view = ANJUTA_VIEW(widget);
- GtkTextIter iter;
AssistWindow* assist_win;
- AssistTip* assist_tip;
- SourceviewCell* cell;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
assist_win = view->priv->sv->priv->assist_win;
- assist_tip = view->priv->sv->priv->assist_tip;
if (assist_win)
{
if (assist_window_filter_keypress(assist_win, event->keyval))
@@ -775,83 +741,7 @@
return TRUE;
}
}
-
- switch (event->keyval)
- {
- case GDK_Shift_L:
- case GDK_Shift_R:
- {
- return TRUE;
- }
- default:
- {
- gboolean retval = (* GTK_WIDGET_CLASS (anjuta_view_parent_class)->key_press_event)(widget, event);
- gtk_text_buffer_get_iter_at_mark(buffer, &iter,
- gtk_text_buffer_get_insert(buffer));
- /* Iter is at the position after the newly added character... */
- gtk_text_iter_backward_char (&iter);
- cell = sourceview_cell_new (&iter, GTK_TEXT_VIEW (view));
- /* Handle char_added signal here */
- if (event->keyval == GDK_Return)
- {
- g_signal_emit_by_name (G_OBJECT(view), "char_added",
- cell, '\n');
- }
- else if (event->keyval == GDK_Tab)
- {
- g_signal_emit_by_name (G_OBJECT(view), "char_added",
- cell, '\t');
- }
- else if (event->keyval == GDK_BackSpace)
- {
- g_signal_emit_by_name(G_OBJECT(view), "char_added",
- cell, '\0');
- }
- else if (event->keyval == GDK_Escape ||
- event->keyval == GDK_Up ||
- event->keyval == GDK_Down)
- {
- if (assist_tip)
- {
- gtk_widget_destroy (GTK_WIDGET(assist_tip));
- g_object_unref (cell);
- return retval;
- }
- }
- else if (event->keyval == GDK_Left || event->keyval == GDK_Right ||
- event->keyval == GDK_Up || event->keyval == GDK_Down ||
- event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down ||
- event->keyval == GDK_Begin || event->keyval == GDK_End)
- {
- /* Ignore those for char_added */
- g_object_unref (cell);
- return retval;
- }
- else
- {
- gchar* unistring = g_new0(gchar, 6);
- gunichar uc = gdk_keyval_to_unicode(event->keyval);
- if (g_unichar_to_utf8(uc, unistring) >= 1)
- {
- guint read, written;
- gchar* string = g_locale_from_utf8(unistring, 1, &read,
- &written, NULL);
- if (string != NULL && read == 1 && written == 1)
- {
- g_signal_emit_by_name (G_OBJECT(view), "char_added",
- cell, string[0]);
- }
- else
- {
- g_object_unref (cell);
- }
- g_free(string);
- }
- g_free(unistring);
- }
- return retval;
- }
- }
+ return (* GTK_WIDGET_CLASS (anjuta_view_parent_class)->key_press_event)(widget, event);
}
static gboolean
Modified: trunk/plugins/sourceview/sourceview-cell.c
==============================================================================
--- trunk/plugins/sourceview/sourceview-cell.c (original)
+++ trunk/plugins/sourceview/sourceview-cell.c Sun Feb 17 10:54:40 2008
@@ -32,7 +32,7 @@
#include <gtk/gtktextview.h>
#include <string.h>
-
+
static void sourceview_cell_class_init(SourceviewCellClass *klass);
static void sourceview_cell_instance_init(SourceviewCell *sp);
static void sourceview_cell_finalize(GObject *object);
@@ -50,8 +50,8 @@
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
sourceview_cell_parent_class = g_type_class_peek_parent(klass);
-
-
+
+
object_class->finalize = sourceview_cell_finalize;
}
@@ -69,7 +69,7 @@
SourceviewCell *cobj;
cobj = SOURCEVIEW_CELL(object);
- gtk_text_iter_free(cobj->priv->iter);
+ gtk_text_iter_free(cobj->priv->iter);
g_slice_free(SourceviewCellPrivate, cobj->priv);
G_OBJECT_CLASS(sourceview_cell_parent_class)->finalize(object);
@@ -89,7 +89,7 @@
return obj;
}
-GtkTextIter*
+GtkTextIter*
sourceview_cell_get_iter (SourceviewCell* cell)
{
return cell->priv->iter;
@@ -99,18 +99,22 @@
icell_get_character(IAnjutaEditorCell* icell, GError** e)
{
SourceviewCell* cell = SOURCEVIEW_CELL(icell);
- gchar outbuf[7];
- int length;
- length = g_unichar_to_utf8(gtk_text_iter_get_char(cell->priv->iter), outbuf);
- outbuf[length] = '\0';
- return g_strdup(outbuf);
+ GtkTextIter* clone = gtk_text_iter_copy (cell->priv->iter);
+ gchar* text = NULL;
+ if (gtk_text_iter_forward_char (clone))
+ text = gtk_text_iter_get_text (cell->priv->iter, clone);
+ return text;
}
static gint
icell_get_length(IAnjutaEditorCell* icell, GError** e)
{
- SourceviewCell* cell = SOURCEVIEW_CELL(icell);
- return g_unichar_to_utf8(gtk_text_iter_get_char(cell->priv->iter), NULL);
+ gchar* text = icell_get_character(icell, e);
+ gint retval = 0;
+ if (text)
+ retval = g_utf8_strlen (text, -1);
+ g_free(text);
+ return retval;
}
static gchar
@@ -118,7 +122,7 @@
{
gchar ch = '\0';
gchar* utf8 = icell_get_character(icell, NULL);
- if (strlen (utf8) > index)
+ if (utf8 && (index == 0 || (strlen (utf8) > index)))
ch = utf8[index];
g_free(utf8);
return ch;
@@ -144,9 +148,9 @@
static
GtkTextAttributes* get_attributes(GtkTextIter* iter, GtkTextView* view)
{
- GtkTextAttributes* atts = gtk_text_view_get_default_attributes(view);
- gtk_text_iter_get_attributes(iter, atts);
- return atts;
+ GtkTextAttributes* atts = gtk_text_view_get_default_attributes(view);
+ gtk_text_iter_get_attributes(iter, atts);
+ return atts;
}
static gchar*
@@ -155,7 +159,7 @@
const gchar* font;
SourceviewCell* cell = SOURCEVIEW_CELL(icell_style);
GtkTextAttributes* atts = get_attributes(cell->priv->iter,
- cell->priv->view);
+ cell->priv->view);
font = pango_font_description_to_string(atts->font);
g_free(atts);
return g_strdup(font);
@@ -168,7 +172,7 @@
SourceviewCell* cell = SOURCEVIEW_CELL(icell_style);
GtkTextAttributes* atts = get_attributes(cell->priv->iter, cell->priv->view);
color = anjuta_util_string_from_color(atts->appearance.fg_color.red,
- atts->appearance.fg_color.green, atts->appearance.fg_color.blue);
+ atts->appearance.fg_color.green, atts->appearance.fg_color.blue);
g_free(atts);
return color;
}
@@ -180,7 +184,7 @@
SourceviewCell* cell = SOURCEVIEW_CELL(icell_style);
GtkTextAttributes* atts = get_attributes(cell->priv->iter, cell->priv->view);
color = anjuta_util_string_from_color(atts->appearance.bg_color.red,
- atts->appearance.bg_color.green, atts->appearance.bg_color.blue);
+ atts->appearance.bg_color.green, atts->appearance.bg_color.blue);
g_free(atts);
return color;
}
@@ -197,15 +201,17 @@
iiter_first(IAnjutaIterable* iter, GError** e)
{
SourceviewCell* cell = SOURCEVIEW_CELL(iter);
- gtk_text_iter_set_offset(cell->priv->iter, 0);
- return TRUE;
+ gboolean retval = gtk_text_iter_is_start (cell->priv->iter);
+ if (!retval)
+ gtk_text_iter_set_offset (cell->priv->iter, 0);
+ return retval;
}
static gboolean
iiter_next(IAnjutaIterable* iter, GError** e)
{
SourceviewCell* cell = SOURCEVIEW_CELL(iter);
-
+
return gtk_text_iter_forward_char(cell->priv->iter);
}
@@ -221,9 +227,10 @@
iiter_last(IAnjutaIterable* iter, GError** e)
{
SourceviewCell* cell = SOURCEVIEW_CELL(iter);
-
- gtk_text_iter_forward_to_end(cell->priv->iter);
- return TRUE;
+ gboolean retval = gtk_text_iter_is_end (cell->priv->iter);
+ if (retval)
+ gtk_text_iter_forward_to_end(cell->priv->iter);
+ return retval;
}
static void
@@ -246,7 +253,7 @@
iiter_set_position (IAnjutaIterable* iter, gint position, GError** e)
{
SourceviewCell* cell = SOURCEVIEW_CELL(iter);
-
+
gtk_text_iter_set_offset (cell->priv->iter, position);
return TRUE;
}
@@ -290,7 +297,7 @@
SourceviewCell* cell = SOURCEVIEW_CELL(iter);
SourceviewCell* other_cell = SOURCEVIEW_CELL(other_iter);
- return gtk_text_iter_compare (cell->priv->iter, other_cell->priv->iter);
+ return gtk_text_iter_compare (cell->priv->iter, other_cell->priv->iter);
}
static gint
@@ -298,6 +305,7 @@
{
SourceviewCell* cell = SOURCEVIEW_CELL(iter);
SourceviewCell* other_cell = SOURCEVIEW_CELL(other_iter);
+
return (gtk_text_iter_get_offset (other_cell->priv->iter)
- gtk_text_iter_get_offset (cell->priv->iter));
}
Modified: trunk/plugins/sourceview/sourceview.c
==============================================================================
--- trunk/plugins/sourceview/sourceview.c (original)
+++ trunk/plugins/sourceview/sourceview.c Sun Feb 17 10:54:40 2008
@@ -118,13 +118,21 @@
}
}
-/* Called when a character is added */
-static void on_document_char_added(AnjutaView* view, IAnjutaIterable* pos,
- gchar ch,
- Sourceview* sv)
+static void on_insert_text (GtkTextBuffer* buffer,
+ GtkTextIter* location,
+ char* text,
+ gint len,
+ Sourceview* sv)
{
- if (ch != '\0')
- g_signal_emit_by_name(G_OBJECT(sv), "char_added", pos, ch);
+ /* We only want ascii characters */
+ if (len > 1)
+ return;
+ else
+ {
+ SourceviewCell* cell = sourceview_cell_new (location,
+ GTK_TEXT_VIEW(sv->priv->view));
+ g_signal_emit_by_name(G_OBJECT(sv), "char_added", cell, text[0]);
+ }
}
/* Called whenever the document is changed */
@@ -541,16 +549,17 @@
{
sv->priv->important_indic =
gtk_text_buffer_create_tag (GTK_TEXT_BUFFER(sv->priv->document),
- IMPORTANT_INDIC,
- "background", "#FFFF00", NULL);
+ IMPORTANT_INDIC,
+ "background", "#FFFF00", NULL);
sv->priv->warning_indic =
gtk_text_buffer_create_tag (GTK_TEXT_BUFFER(sv->priv->document),
- WARNING_INDIC,
- "foreground", "#00FF00", NULL);
+ WARNING_INDIC,
+ "foreground", "#00FF00", NULL);
sv->priv->critical_indic =
gtk_text_buffer_create_tag (GTK_TEXT_BUFFER(sv->priv->document),
- CRITICAL_INDIC,
- "foreground", "#FF0000", "underline", PANGO_UNDERLINE_ERROR, NULL);
+ CRITICAL_INDIC,
+ "foreground", "#FF0000", "underline",
+ PANGO_UNDERLINE_ERROR, NULL);
}
@@ -578,11 +587,11 @@
G_CALLBACK(on_document_saved), sv);
g_signal_connect(G_OBJECT(sv->priv->document), "saving",
G_CALLBACK(on_document_saving), sv);
+ g_signal_connect_after (G_OBJECT(sv->priv->document), "insert-text",
+ G_CALLBACK(on_insert_text), sv);
/* Create View instance */
sv->priv->view = ANJUTA_VIEW(anjuta_view_new(sv));
- g_signal_connect_after(G_OBJECT(sv->priv->view), "char_added",
- G_CALLBACK(on_document_char_added), sv);
#if HAVE_TOOLTIP_API
g_signal_connect (G_OBJECT(sv->priv->view), "query-tooltip",
G_CALLBACK (on_sourceview_hover_over), sv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]