Expose MooIndenter::character virtual method

This commit is contained in:
Yevgen Muntyan 2008-09-18 21:23:33 -05:00
parent 447c053bb5
commit f382fef080
9 changed files with 59 additions and 38 deletions

View File

@ -1,5 +1,5 @@
BOOL:BOXED
BOOL:BOXED,UINT
BOOL:BOXED,STRING
BOOL:INT
BOOL:OBJECT,BOOLEAN
BOOL:STRING
@ -13,8 +13,8 @@ VOID:OBJECT
VOID:OBJECT,BOXED
VOID:OBJECT,OBJECT
VOID:STRING
VOID:STRING,BOXED
VOID:STRING,OBJECT
VOID:UINT
VOID:UINT,BOXED
VOID:UINT,POINTER
VOID:VOID

View File

@ -269,7 +269,7 @@ moo_edit_init (MooEdit *edit)
edit->priv->actions = moo_action_collection_new ("MooEdit", "MooEdit");
indent = moo_indenter_new (edit, NULL);
indent = moo_indenter_new (edit);
moo_text_view_set_indenter (MOO_TEXT_VIEW (edit), indent);
g_object_unref (indent);
}

View File

@ -35,7 +35,7 @@ static void moo_indenter_get_property (GObject *object,
GParamSpec *pspec);
static void character_default (MooIndenter *indenter,
gunichar inserted_char,
const char *inserted_char,
GtkTextIter *where);
static void config_changed_default (MooIndenter *indenter,
guint setting_id,
@ -132,9 +132,9 @@ moo_indenter_class_init (MooIndenterClass *klass)
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (MooIndenterClass, character),
NULL, NULL,
_moo_marshal_VOID__UINT_BOXED,
G_TYPE_NONE, 1,
G_TYPE_UINT,
_moo_marshal_VOID__STRING_BOXED,
G_TYPE_NONE, 2,
G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE,
GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE);
}
@ -274,18 +274,17 @@ config_notify (MooIndenter *indenter,
void
moo_indenter_character (MooIndenter *indenter,
gunichar inserted_char,
GtkTextIter *where)
moo_indenter_character (MooIndenter *indenter,
const char *inserted_char,
GtkTextIter *where)
{
g_return_if_fail (MOO_IS_INDENTER (indenter));
MOO_INDENTER_GET_CLASS(indenter)->character (indenter, inserted_char, where);
}
MooIndenter*
moo_indenter_new (gpointer doc,
G_GNUC_UNUSED const char *name)
MooIndenter *
moo_indenter_new (gpointer doc)
{
g_return_val_if_fail (!doc || MOO_IS_EDIT (doc), NULL);
return g_object_new (MOO_TYPE_INDENTER, "doc", doc, NULL);
@ -391,16 +390,18 @@ compute_line_offset (GtkTextIter *dest,
static void
character_default (MooIndenter *indenter,
gunichar inserted_char,
GtkTextIter *where)
character_default (MooIndenter *indenter,
const char *inserted_char,
GtkTextIter *where)
{
char *indent_string = NULL;
GtkTextBuffer *buffer = gtk_text_iter_get_buffer (where);
guint offset;
GtkTextIter iter;
if (inserted_char != '\n')
g_return_if_fail (inserted_char != NULL);
if (*inserted_char != '\n')
return;
iter = *where;

View File

@ -50,22 +50,21 @@ struct _MooIndenterClass
guint setting_id,
GParamSpec *pspec);
void (*character) (MooIndenter *indenter,
gunichar inserted_char,
const char *inserted_char,
GtkTextIter *where);
};
GType moo_indenter_get_type (void) G_GNUC_CONST;
MooIndenter *moo_indenter_new (gpointer doc,
const char *name);
MooIndenter *moo_indenter_new (gpointer doc);
char *moo_indenter_make_space (MooIndenter *indenter,
guint len,
guint start);
void moo_indenter_character (MooIndenter *indenter,
gunichar inserted_char,
const char *inserted_char,
GtkTextIter *where);
void moo_indenter_tab (MooIndenter *indenter,
GtkTextBuffer *buffer);

View File

@ -1513,11 +1513,10 @@ handle_enter (MooTextView *view,
if (has_selection)
gtk_text_buffer_delete (buffer, &start, &end);
/* XXX insert "\r\n" on windows? */
gtk_text_buffer_insert (buffer, &start, "\n", 1);
if (indent)
moo_indenter_character (view->priv->indenter, '\n', &start);
moo_indenter_character (view->priv->indenter, "\n", &start);
gtk_text_buffer_end_user_action (buffer);

View File

@ -169,7 +169,7 @@ struct _MooTextViewPrivate {
/* key press handler sets this flag in order to distinguish typed in
characters in buffer's insert-text signal */
gboolean in_key_press;
gunichar char_inserted;
char *char_inserted;
int char_inserted_offset;
gunichar *word_chars;

View File

@ -137,7 +137,7 @@ static void insert_text_cb (MooTextView *view,
gint len);
static gboolean moo_text_view_char_inserted (MooTextView *view,
GtkTextIter *where,
guint character);
const char *character);
static void moo_text_view_delete_selection (MooTextView *view);
static void set_manage_clipboard (MooTextView *view,
@ -622,10 +622,10 @@ static void moo_text_view_class_init (MooTextViewClass *klass)
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (MooTextViewClass, char_inserted),
g_signal_accumulator_true_handled, NULL,
_moo_marshal_BOOLEAN__BOXED_UINT,
_moo_marshal_BOOLEAN__BOXED_STRING,
G_TYPE_BOOLEAN, 2,
GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
G_TYPE_UINT);
G_TYPE_STRING | G_SIGNAL_TYPE_STATIC_SCOPE);
signals[CURSOR_MOVED] =
g_signal_new ("cursor-moved",
@ -860,6 +860,8 @@ moo_text_view_finalize (GObject *object)
for (i = 0; i < MOO_TEXT_VIEW_N_COLORS; ++i)
g_free (view->priv->colors[i]);
g_free (view->priv->char_inserted);
G_OBJECT_CLASS (moo_text_view_parent_class)->finalize (object);
}
@ -1368,7 +1370,7 @@ insert_text_cb (MooTextView *view,
if (view->priv->in_key_press && g_utf8_strlen (text, len) == 1)
{
view->priv->in_key_press = FALSE;
view->priv->char_inserted = g_utf8_get_char (text);
view->priv->char_inserted = g_strdup (text);
view->priv->char_inserted_offset = gtk_text_iter_get_offset (iter);
}
}
@ -1386,18 +1388,19 @@ _moo_text_view_check_char_inserted (MooTextView *view)
view->priv->char_inserted_offset);
g_signal_emit (view, signals[CHAR_INSERTED], 0,
&iter, (guint) view->priv->char_inserted,
&iter, view->priv->char_inserted,
&result);
view->priv->char_inserted = 0;
g_free (view->priv->char_inserted);
view->priv->char_inserted = NULL;
}
}
static gboolean
moo_text_view_char_inserted (MooTextView *view,
GtkTextIter *where,
guint character)
moo_text_view_char_inserted (MooTextView *view,
GtkTextIter *where,
const char *character)
{
if (view->priv->indenter)
{

View File

@ -60,7 +60,7 @@ struct _MooTextViewClass
gboolean (* char_inserted) (MooTextView *view,
GtkTextIter *where, /* points to position after the char */
guint character); /* gunichar */
const char *character); /* single character as string */
gboolean (* line_mark_clicked) (MooTextView *view,
int line);

View File

@ -553,15 +553,16 @@
;; From mooindenter.h
(ifndef pygtk-2.6
(define-function moo_indenter_new
(c-name "moo_indenter_new")
(is-constructor-of "MooIndenter")
(return-type "MooIndenter*")
(parameters
'("MooEdit*" "doc")
'("const-char*" "name")
(properties
'("doc")
)
)
)
(define-method make_space
(of-object "MooIndenter")
@ -578,7 +579,7 @@
(c-name "moo_indenter_character")
(return-type "none")
(parameters
'("gunichar" "inserted_char")
'("const-char*" "inserted_char")
'("GtkTextIter*" "where")
)
)
@ -604,6 +605,24 @@
)
)
(define-virtual config_changed
(of-object "MooIndenter")
(return-type "none")
(parameters
'("guint" "setting_id")
'("GParamSpec*" "pspec")
)
)
(define-virtual character
(of-object "MooIndenter")
(return-type "none")
(parameters
'("const-char*" "inserted_char")
'("GtkTextIter*" "where")
)
)
(define-function moo_iter_get_blank_offset
(c-name "moo_iter_get_blank_offset")
(return-type "int")