Exemplo n.º 1
0
/**
 * ide_indenter_is_trigger:
 * @self: an #IdeIndenter
 * @event: a #GdkEventKey
 *
 * Determines if @event should trigger an indentation request. If %TRUE is
 * returned then ide_indenter_format() will be called.
 *
 * Returns: %TRUE if @event should trigger an indentation request.
 */
gboolean
ide_indenter_is_trigger (IdeIndenter *self,
                         GdkEventKey *event)
{
  g_return_val_if_fail (IDE_IS_INDENTER (self), FALSE);
  g_return_val_if_fail (event, FALSE);

  return IDE_INDENTER_GET_IFACE (self)->is_trigger (self, event);
}
Exemplo n.º 2
0
/**
 * ide_indenter_format:
 * @text_view: A #GtkTextView
 * @begin: A #GtkTextIter for the beginning region of text to replace.
 * @end: A #GtkTextIter for the end region of text to replace.
 * @cursor_offset: (out): The offset in characters from @end to place the
 *   cursor. Negative values are okay.
 * @event: The #GdkEventKey that triggered the event.
 *
 * This function performs an indentation for the key press activated by @event.
 * The implementation is free to move the @begin and @end iters to swallow
 * adjacent content. The result, a string, is the contents that will replace
 * the content inbetween @begin and @end.
 *
 * @cursor_offset may be set to jump the cursor starting from @end. Negative
 * values are allowed.
 *
 * Returns: (nullable) (transfer full): A string containing the replacement text, or %NULL.
 */
gchar *
ide_indenter_format (IdeIndenter *self,
                     GtkTextView *text_view,
                     GtkTextIter *begin,
                     GtkTextIter *end,
                     gint        *cursor_offset,
                     GdkEventKey *event)
{
  g_return_val_if_fail (IDE_IS_INDENTER (self), NULL);
  g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
  g_return_val_if_fail (begin, NULL);
  g_return_val_if_fail (end, NULL);
  g_return_val_if_fail (cursor_offset, NULL);
  g_return_val_if_fail (event, NULL);

  return IDE_INDENTER_GET_IFACE (self)->format (self, text_view, begin, end, cursor_offset, event);
}
Exemplo n.º 3
0
/**
 * ide_indenter_format:
 * @self: (nullable): An #IdeIndenter or %NULL for the fallback
 * @text_view: a #GtkTextView
 * @begin: a #GtkTextIter for the beginning region of text to replace.
 * @end: a #GtkTextIter for the end region of text to replace.
 * @cursor_offset: (out): The offset in characters from @end to place the
 *   cursor. Negative values are okay.
 * @event: The #GdkEventKey that triggered the event.
 *
 * This function performs an indentation for the key press activated by @event.
 * The implementation is free to move the @begin and @end iters to swallow
 * adjacent content. The result, a string, is the contents that will replace
 * the content inbetween @begin and @end.
 *
 * @cursor_offset may be set to jump the cursor starting from @end. Negative
 * values are allowed.
 *
 * If @self is %NULL, the fallback indenter is used, which tries to mimic the
 * indentation style of #GtkSourceView.
 *
 * Returns: (nullable) (transfer full): A string containing the replacement
 *   text, or %NULL.
 *
 * Since: 3.32
 */
gchar *
ide_indenter_format (IdeIndenter *self,
                     GtkTextView *text_view,
                     GtkTextIter *begin,
                     GtkTextIter *end,
                     gint        *cursor_offset,
                     GdkEventKey *event)
{
  g_return_val_if_fail (!self || IDE_IS_INDENTER (self), NULL);
  g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
  g_return_val_if_fail (begin != NULL, NULL);
  g_return_val_if_fail (end != NULL, NULL);
  g_return_val_if_fail (cursor_offset != NULL, NULL);
  g_return_val_if_fail (event != NULL, NULL);

  if (self == NULL)
    return ide_indenter_mimic_source_view (text_view, begin, end, cursor_offset, event);
  else
    return IDE_INDENTER_GET_IFACE (self)->format (self, text_view, begin, end, cursor_offset, event);
}
Exemplo n.º 4
0
/**
 * ide_indenter_is_trigger:
 * @self: (nullable): an #IdeIndenter or %NULL for the fallback
 * @event: a #GdkEventKey
 *
 * Determines if @event should trigger an indentation request. If %TRUE is
 * returned then ide_indenter_format() will be called.
 *
 * If @self is %NULL, the fallback indenter is used, which tries to mimic
 * the default indentation style of #GtkSourceView.
 *
 * Returns: %TRUE if @event should trigger an indentation request.
 *
 * Since: 3.32
 */
gboolean
ide_indenter_is_trigger (IdeIndenter *self,
                         GdkEventKey *event)
{
  g_return_val_if_fail (!self || IDE_IS_INDENTER (self), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  if (self == NULL)
    {
      switch (event->keyval)
        {
        case GDK_KEY_KP_Enter:
        case GDK_KEY_Return:
          return TRUE;

        default:
          return FALSE;
        }
    }

  return IDE_INDENTER_GET_IFACE (self)->is_trigger (self, event);
}