static void
ide_highlight_engine__buffer_insert_text_cb (IdeHighlightEngine *self,
        GtkTextIter        *location,
        gchar              *text,
        gint                len,
        IdeBuffer          *buffer)
{
    GtkTextBuffer *text_buffer = (GtkTextBuffer *)buffer;
    GtkTextIter begin;
    GtkTextIter end;

    IDE_ENTRY;

    g_assert (IDE_IS_HIGHLIGHT_ENGINE (self));
    g_assert (location);
    g_assert (text);
    g_assert (IDE_IS_BUFFER (buffer));
    g_assert (GTK_IS_TEXT_BUFFER (text_buffer));

    /*
     * Backward the begin iter len characters from location
     * (location points to the end of the string) in order to get
     * the iter position where our inserted text was started.
     */
    begin = *location;
    gtk_text_iter_backward_chars (&begin, g_utf8_strlen (text, len));

    end = *location;

    invalidate_and_highlight (self, &begin, &end);

    IDE_EXIT;
}
Esempio n. 2
0
static gboolean locate_color(Tdocument *doc, const GtkTextIter *iter) {
	Tin_html_tag iht;
	gboolean retval=FALSE;
	GtkTextIter leftiter=*iter, rightiter, maxiter = *iter;
	DEBUG_MSG("locate_color, started\n");
	rec_color.found = FALSE;
	gtk_text_iter_backward_chars(&maxiter, 8);
	/* first we look to the left for a #, and we look back at max. 8 chars (7 would be good enough) */
	iht.findchar = '#';
	iht.prevchar = '\n';
	iht.ignore_if_prevchar = '\0';
	if (gtk_text_iter_backward_find_char(&leftiter,
					(GtkTextCharPredicate)iter_char_search_lcb,&iht,&maxiter)) 
					{
		gchar *text;
		rightiter = leftiter;
		gtk_text_iter_forward_chars(&rightiter, 7);
		text = gtk_text_buffer_get_text(doc->buffer,&leftiter,&rightiter,FALSE);
		DEBUG_MSG("locate_color,is '%s' a color?\n",text);
		if (text) {
			retval = string_is_color(text);
			if (retval) {
				rec_color.so = gtk_text_iter_get_offset(&leftiter);
				rec_color.eo = gtk_text_iter_get_offset(&rightiter);
				rec_color.found = TRUE;
				rec_color.doc = doc;
				DEBUG_MSG("found color from so=%d to eo=%d\n",rec_color.so, rec_color.eo);
			}
			g_free(text);
		}
	}
	return retval;
}
Esempio n. 3
0
//==========================================================================
  char GUI_edi_RdChr (MemObj *mo, int offset) {
//==========================================================================
/// \code
/// read char near cursor;
/// offset  0 = char right of cursor
/// offset -1 = char left of cursor
/// returns  '\0' for out-of-file-positions.
/// returns  -1 for a multibyte-character
/// \endcode

  GtkTextMark *mk1;
  GtkTextIter it1;
  gboolean    b1;
  long        uc;
  // char        c1;


  // printf("GUI_edi_RdChr |%c| %d\n",c1,cpos);

  // set GUI_ed1_view GUI_ed1_buff
  if(mo) {   // for internal call: mo=NULL
    if(GUI_ed1_decode(mo)) return -1;
  }


  // get mark at CurPos
  mk1 = gtk_text_buffer_get_mark (GUI_ed1_buff, "insert");

  // iter at CurPos
  gtk_text_buffer_get_iter_at_mark (GUI_ed1_buff, &it1, mk1);

  // move iter back
  if(offset < 0) {
    b1 = gtk_text_iter_backward_chars (&it1, -offset);
    // false if left of 1. char; returns Null !.
    if(b1 == FALSE) return '\0';
  }

  // move iter forw
  if(offset > 0) {
    b1 = gtk_text_iter_forward_chars (&it1, offset);
    // false if left of 1. char; returns Null !.
    if(b1 == FALSE) return '\0';
  }


  // get unicode-char at curpos
  uc = gtk_text_iter_get_char (&it1);

  if((uc > 127)||(uc < 0)) return -1;

  // printf("ex GUI_edi_RdChr |%ld|\n",uc);

  return uc;

}
Esempio n. 4
0
File: color.c Progetto: Moeryn/bmc
/**
 * \fn void color(BrailleMusicEditor *editor)
 * \brief This function color the differents types of braille music notations
 * in the textview.
 * \param editor The GUI structure.
 * 
 * This function will color the diffrents types of braille music notations present in text. 
 */
void color(BrailleMusicEditor *editor)
{
    GtkTextIter start, end;
    GtkTextIter start_match, end_match, start_match2, start_match3;

    GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->textview)); 
    
    gtk_text_buffer_get_start_iter(buffer, &start);
    gtk_text_buffer_get_end_iter(buffer, &end);
    
    gtk_text_buffer_get_start_iter(buffer, &start_match);
    gtk_text_buffer_get_start_iter(buffer, &end_match);
    
    set_tags(buffer);
    init_braille_table();
    
    do {
	gtk_text_iter_forward_chars(&end_match, 1);
	gchar *c = gtk_text_iter_get_slice(&start_match, &end_match);
	
	start_match2 = start_match;
	gtk_text_iter_backward_chars(&start_match2, 1);
	gchar *c2 = gtk_text_iter_get_slice(&start_match2, &end_match);
	
	start_match3 = start_match2;
	gtk_text_iter_backward_chars(&start_match3, 1);
	gchar *c3 = gtk_text_iter_get_slice(&start_match3, &end_match);

	gchar *type;
	if((type = g_hash_table_lookup(braille_table, c3)) != NULL) {
	    gtk_text_buffer_remove_all_tags(buffer, &start_match3, &end_match);
	    gtk_text_buffer_apply_tag_by_name(buffer, type, &start_match3, &end_match);
	}
	else if((type = g_hash_table_lookup(braille_table, c2)) != NULL) {
	    gtk_text_buffer_remove_all_tags(buffer, &start_match2, &end_match);
	    gtk_text_buffer_apply_tag_by_name(buffer, type, &start_match2, &end_match);
	}
	else if((type = g_hash_table_lookup(braille_table, c)) != NULL) {
	    gtk_text_buffer_apply_tag_by_name(buffer, type, &start_match, &end_match);
	}
	
    } while(gtk_text_iter_forward_chars(&start_match, 1));
}
bool CheckCapitalization::is_reference(GtkTextIter iter)
/*
Looks whether the text at iter looks like a reference.
A reference, e.g. Mt.5.5 or Mt.5:5 or John 10:5 follows a certain pattern,
while going through it. Some references are given without the bookname, e.g.
"10.5". Handle these too.
Patterns:
- digit, dot/colon, digit.
*/
{
  GtkTextIter iter0 = iter;
  gtk_text_iter_backward_chars(&iter0, 4);
  gtk_text_iter_forward_chars(&iter, 4);
  ustring reference = gtk_text_iter_get_text(&iter0, &iter);
  return text_contains_reference(reference);
}
Esempio n. 6
0
/* Helper function: extract some characters of context around the match, with
 the match itself highlighted in bold. String must be freed. */
static gchar *
extract_context(GtkTextBuffer *buffer, GtkTextIter *match_start, GtkTextIter *match_end)
{
	GtkTextIter context_start = *match_start, context_end = *match_end;

	/* Create a larger range to extract the context */
	gtk_text_iter_backward_chars(&context_start, 8);
	gtk_text_iter_forward_chars(&context_end, 32);

	/* Get the surrounding text as context */
	gchar *before = gtk_text_buffer_get_text(buffer, &context_start, match_start, TRUE);
	gchar *term = gtk_text_buffer_get_text(buffer, match_start, match_end, TRUE);
	gchar *after = gtk_text_buffer_get_text(buffer, match_end, &context_end, TRUE);
	gchar *context = g_strconcat(before, "<b>", term, "</b>", after, NULL);
	g_strdelimit(context, "\n\r\t", ' ');
	g_free(before);
	g_free(term);
	g_free(after);

	return context;
}
Esempio n. 7
0
void
load_file (const gchar *demoname,
           const gchar *filename)
{
  GtkTextBuffer *info_buffer, *source_buffer;
  GtkTextIter start, end;
  char *resource_filename;
  GError *err = NULL;
  int state = 0;
  gboolean in_para = 0;
  gchar **lines;
  GBytes *bytes;
  gint i;

  if (!g_strcmp0 (current_file, filename))
    return;

  remove_data_tabs ();

  add_data_tab (demoname);

  g_free (current_file);
  current_file = g_strdup (filename);

  info_buffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_create_tag (info_buffer, "title",
                              "font", "Sans 18",
                              "pixels-below-lines", 10,
                              NULL);

  source_buffer = gtk_text_buffer_new (NULL);
  gtk_text_buffer_create_tag (source_buffer, "comment",
                              "foreground", "DodgerBlue",
                              NULL);
  gtk_text_buffer_create_tag (source_buffer, "type",
                              "foreground", "ForestGreen",
                              NULL);
  gtk_text_buffer_create_tag (source_buffer, "string",
                              "foreground", "RosyBrown",
                              "weight", PANGO_WEIGHT_BOLD,
                              NULL);
  gtk_text_buffer_create_tag (source_buffer, "control",
                              "foreground", "purple",
                              NULL);
  gtk_text_buffer_create_tag (source_buffer, "preprocessor",
                              "style", PANGO_STYLE_OBLIQUE,
                              "foreground", "burlywood4",
                              NULL);
  gtk_text_buffer_create_tag (source_buffer, "function",
                              "weight", PANGO_WEIGHT_BOLD,
                              "foreground", "DarkGoldenrod4",
                              NULL);

  resource_filename = g_strconcat ("/sources/", filename, NULL);
  bytes = g_resources_lookup_data (resource_filename, 0, &err);
  g_free (resource_filename);

  if (bytes == NULL)
    {
      g_warning ("Cannot open source for %s: %s\n", filename, err->message);
      g_error_free (err);
      return;
    }

  lines = g_strsplit (g_bytes_get_data (bytes, NULL), "\n", -1);
  g_bytes_unref (bytes);

  gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0);
  for (i = 0; lines[i] != NULL; i++)
    {
      gchar *p;
      gchar *q;
      gchar *r;

      /* Make sure \r is stripped at the end for the poor windows people */
      lines[i] = g_strchomp (lines[i]);

      p = lines[i];
      switch (state)
        {
        case 0:
          /* Reading title */
          while (*p == '/' || *p == '*' || g_ascii_isspace (*p))
            p++;
          r = p;
          while (*r != '\0')
            {
              while (*r != '/' && *r != ':' && *r != '\0')
                r++;
              if (*r == '/')
                {
                  r++;
                  p = r;
                }
              if (r[0] == ':' && r[1] == ':')
                *r = '\0';
            }
          q = p + strlen (p);
          while (q > p && g_ascii_isspace (*(q - 1)))
            q--;


          if (q > p)
            {
              int len_chars = g_utf8_pointer_to_offset (p, q);

              end = start;

              g_assert (strlen (p) >= q - p);
              gtk_text_buffer_insert (info_buffer, &end, p, q - p);
              start = end;

              gtk_text_iter_backward_chars (&start, len_chars);
              gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);

              start = end;

              while (*p && *p != '\n') p++;

              state++;
            }
          break;

        case 1:
          /* Reading body of info section */
          while (g_ascii_isspace (*p))
            p++;
          if (*p == '*' && *(p + 1) == '/')
            {
              gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
              state++;
            }
          else
            {
              int len;

              while (*p == '*' || g_ascii_isspace (*p))
                p++;

              len = strlen (p);
              while (g_ascii_isspace (*(p + len - 1)))
                len--;

              if (len > 0)
                {
                  if (in_para)
                    gtk_text_buffer_insert (info_buffer, &start, " ", 1);

                  g_assert (strlen (p) >= len);
                  gtk_text_buffer_insert (info_buffer, &start, p, len);
                  in_para = 1;
                }
              else
                {
                  gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
                  in_para = 0;
                }
            }
          break;

        case 2:
          /* Skipping blank lines */
          while (g_ascii_isspace (*p))
            p++;
          if (*p)
            {
              p = lines[i];
              state++;
              /* Fall through */
            }
          else
            break;

        case 3:
          /* Reading program body */
          gtk_text_buffer_insert (source_buffer, &start, p, -1);
          gtk_text_buffer_insert (source_buffer, &start, "\n", 1);
          break;
        }
    }

  fontify (source_buffer);

  g_strfreev (lines);

  gtk_text_view_set_buffer (GTK_TEXT_VIEW (info_view), info_buffer);
  g_object_unref (info_buffer);
  gtk_text_view_set_buffer (GTK_TEXT_VIEW (source_view), source_buffer);
  g_object_unref (source_buffer);
}
Esempio n. 8
0
void
load_file (const gchar *filename)
{
    FILE *file;
    GtkTextIter start, end;
    char *full_filename;
    GError *err = NULL;
    GString *buffer = g_string_new (NULL);
    int state = 0;
    gboolean in_para = 0;

    if (current_file && !strcmp (current_file, filename))
    {
        g_string_free (buffer, TRUE);
        return;
    }

    g_free (current_file);
    current_file = g_strdup (filename);

    gtk_text_buffer_get_bounds (info_buffer, &start, &end);
    gtk_text_buffer_delete (info_buffer, &start, &end);

    gtk_text_buffer_get_bounds (source_buffer, &start, &end);
    gtk_text_buffer_delete (source_buffer, &start, &end);

    full_filename = demo_find_file (filename, &err);
    if (!full_filename)
    {
        g_warning ("%s", err->message);
        g_error_free (err);
        return;
    }

    file = g_fopen (full_filename, "r");

    if (!file)
        g_warning ("Cannot open %s: %s\n", full_filename, g_strerror (errno));

    g_free (full_filename);

    if (!file)
        return;

    gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0);
    while (read_line (file, buffer))
    {
        gchar *p = buffer->str;
        gchar *q;
        gchar *r;

        switch (state)
        {
        case 0:
            /* Reading title */
            while (*p == '/' || *p == '*' || g_ascii_isspace (*p))
                p++;
            r = p;
            while (*r != '/' && strlen (r))
                r++;
            if (strlen (r) > 0)
                p = r + 1;
            q = p + strlen (p);
            while (q > p && g_ascii_isspace (*(q - 1)))
                q--;

            if (q > p)
            {
                int len_chars = g_utf8_pointer_to_offset (p, q);

                end = start;

                g_assert (strlen (p) >= q - p);
                gtk_text_buffer_insert (info_buffer, &end, p, q - p);
                start = end;

                gtk_text_iter_backward_chars (&start, len_chars);
                gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);

                start = end;

                state++;
            }
            break;

        case 1:
            /* Reading body of info section */
            while (g_ascii_isspace (*p))
                p++;
            if (*p == '*' && *(p + 1) == '/')
            {
                gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
                state++;
            }
            else
            {
                int len;

                while (*p == '*' || g_ascii_isspace (*p))
                    p++;

                len = strlen (p);
                while (g_ascii_isspace (*(p + len - 1)))
                    len--;

                if (len > 0)
                {
                    if (in_para)
                        gtk_text_buffer_insert (info_buffer, &start, " ", 1);

                    g_assert (strlen (p) >= len);
                    gtk_text_buffer_insert (info_buffer, &start, p, len);
                    in_para = 1;
                }
                else
                {
                    gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
                    in_para = 0;
                }
            }
            break;

        case 2:
            /* Skipping blank lines */
            while (g_ascii_isspace (*p))
                p++;
            if (*p)
            {
                p = buffer->str;
                state++;
                /* Fall through */
            }
            else
                break;

        case 3:
            /* Reading program body */
            gtk_text_buffer_insert (source_buffer, &start, p, -1);
            gtk_text_buffer_insert (source_buffer, &start, "\n", 1);
            break;
        }
    }

    fclose (file);

    fontify ();

    g_string_free (buffer, TRUE);
}
Esempio n. 9
0
gboolean
acwin_check_keypress(BluefishTextView * btv, GdkEventKey * event)
{
	DBG_AUTOCOMP("got keyval %c\n", event->keyval);
	if ((event->state & GDK_CONTROL_MASK) || (event->state & GDK_MOD1_MASK)) {
		DBG_AUTOCOMP("a modifier is active (state=%d), don't handle the keypress\n", event->state);
		return FALSE;
	}
	switch (event->keyval) {
	case GDK_Return:{
			GtkTreeSelection *selection;
			GtkTreeIter it;
			GtkTreeModel *model;
			BluefishTextView *master = BLUEFISH_TEXT_VIEW(btv->master);
			selection = gtk_tree_view_get_selection(ACWIN(btv->autocomp)->tree);
			if (selection && gtk_tree_selection_get_selected(selection, &model, &it)) {
				gchar *string;
				gint stringlen;
				gint existing_len, prefix_len;
				guint pattern_id;
				gint backup_chars = 0;
				gboolean trigger_new_autocomp_popup=FALSE;
				gtk_tree_model_get(model, &it, 1, &string, -1);
				/*g_print("context %d has patternhash %p, string=%s\n",ACWIN(btv->autocomp)->contextnum, g_array_index(btv->bflang->st->contexts, Tcontext, ACWIN(btv->autocomp)->contextnum).patternhash, string); */
				if (g_array_index
					(master->bflang->st->contexts, Tcontext, ACWIN(btv->autocomp)->contextnum).patternhash) {
					/*g_print("looking in context %d patternhash for '%s'\n",ACWIN(btv->autocomp)->contextnum, string); */
					pattern_id =
						GPOINTER_TO_INT(g_hash_table_lookup
										(g_array_index
										 (master->bflang->st->contexts, Tcontext,
										  ACWIN(btv->autocomp)->contextnum).patternhash, string));
					DBG_AUTOCOMP("got pattern_id=%d\n", pattern_id);
					if (pattern_id) {
						GSList *tmpslist =
							g_array_index(master->bflang->st->matches, Tpattern, pattern_id).autocomp_items;
						/* a pattern MAY have multiple autocomplete items. This code is not efficient if in the future some
						   patterns would have many autocomplete items. I don't expect this, so I leave this as it is right now  */
						while (tmpslist) {
							Tpattern_autocomplete *pac = tmpslist->data;
							if (g_strcmp0(string, pac->autocomplete_string) == 0) {
								backup_chars = pac->autocomplete_backup_cursor;
								trigger_new_autocomp_popup = (pac->trigger_new_autocomp_popup==1);
							}
							tmpslist = g_slist_next(tmpslist);
						}
					}
				}
				stringlen = strlen(string);
				prefix_len = strlen(ACWIN(btv->autocomp)->prefix);
				existing_len = get_existing_end_len(btv, string, prefix_len);

				DBG_AUTOCOMP("acwin_check_keypress: ENTER: insert %s\n",
							 string + prefix_len);
				string[stringlen - existing_len] = '\0';
				/* see if there are any \n characters in the autocompletion string, and add the current indenting to them */
				string = string_maintain_indenting(btv, string, &backup_chars);
				gtk_text_buffer_insert_at_cursor(btv->buffer, string + prefix_len, -1);
				if (backup_chars != 0) {
					GtkTextIter iter;
					gtk_text_buffer_get_iter_at_mark(btv->buffer, &iter, gtk_text_buffer_get_insert(btv->buffer));
					if (backup_chars-existing_len > 0 && gtk_text_iter_backward_chars(&iter, backup_chars-existing_len)) {
						DBG_AUTOCOMP("move cursor %d chars back!\n", backup_chars);
						gtk_text_buffer_place_cursor(btv->buffer, &iter);
					}
				}
				if (trigger_new_autocomp_popup) {
					g_idle_add(trigger_new_autocomp_idle, btv);
				}
				g_free(string);
			}
			acwin_cleanup(btv);
			return TRUE;
		}
		break;
	case GDK_Tab:
		if (ACWIN(btv->autocomp)->newprefix
			&& strlen(ACWIN(btv->autocomp)->newprefix) > strlen(ACWIN(btv->autocomp)->prefix)) {
			gtk_text_buffer_insert_at_cursor(gtk_text_view_get_buffer(GTK_TEXT_VIEW(btv)),
											 ACWIN(btv->autocomp)->newprefix +
											 strlen(ACWIN(btv->autocomp)->prefix), -1);
		}
		/* now we have to re-position the autocomplete window */
		autocomp_run(btv, FALSE);
		return TRUE;
		break;
	case GDK_Right:
	case GDK_KP_Right:
	case GDK_Left:
	case GDK_KP_Left:
		acwin_cleanup(btv);
		return FALSE;
		break;
	case GDK_Escape:
		acwin_cleanup(btv);
		return TRUE;
		break;
	case GDK_Up:
	case GDK_Down:
	case GDK_Page_Down:
	case GDK_Page_Up:
	case GDK_Home:
	case GDK_End:
		if (acwin_move_selection(btv, event->keyval))
			return TRUE;
		break;
	}

	return FALSE;
}
void
_ide_source_view_apply_movement (IdeSourceView         *self,
                                 IdeSourceViewMovement  movement,
                                 gboolean               extend_selection,
                                 gboolean               exclusive,
                                 guint                  count,
                                 gunichar               command,
                                 gunichar               modifier,
                                 gunichar               search_char,
                                 gint                  *target_offset)
{
  Movement mv = { 0 };
  GtkTextBuffer *buffer;
  GtkTextMark *insert;
  gsize i;

  g_return_if_fail (IDE_IS_SOURCE_VIEW (self));

#ifdef IDE_ENABLE_TRACE
  {
    GEnumValue *enum_value;
    GEnumClass *enum_class;

    enum_class = g_type_class_ref (IDE_TYPE_SOURCE_VIEW_MOVEMENT);
    enum_value = g_enum_get_value (enum_class, movement);
    IDE_TRACE_MSG ("movement(%s, extend_selection=%s, exclusive=%s, count=%u)",
                   enum_value->value_nick,
                   extend_selection ? "YES" : "NO",
                   exclusive ? "YES" : "NO",
                   count);
    g_type_class_unref (enum_class);
  }
#endif

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
  insert = gtk_text_buffer_get_insert (buffer);

  mv.self = self;
  mv.target_offset = target_offset;
  mv.type = movement;
  mv.extend_selection = extend_selection;
  mv.exclusive = exclusive;
  mv.count = count;
  mv.ignore_select = FALSE;
  mv.ignore_target_offset = FALSE;
  mv.command = command;
  mv.modifier = modifier;

  ide_source_view_movements_get_selection (&mv);

  switch (movement)
    {
    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_OFFSET:
      gtk_text_iter_backward_chars (&mv.insert, MAX (1, mv.count));
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_OFFSET:
      gtk_text_iter_forward_chars (&mv.insert, MAX (1, mv.count));
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NTH_CHAR:
      ide_source_view_movements_nth_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_CHAR:
      ide_source_view_movements_previous_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_CHAR:
      ide_source_view_movements_next_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_FIRST_CHAR:
      ide_source_view_movements_first_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_FIRST_NONSPACE_CHAR:
      ide_source_view_movements_first_nonspace_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_MIDDLE_CHAR:
      ide_source_view_movements_middle_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_LAST_CHAR:
      ide_source_view_movements_last_char (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_START:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_full_word_start (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_START:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_full_word_start (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_FULL_WORD_END:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_full_word_end (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_FULL_WORD_END:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_full_word_end (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_SUB_WORD_START:
      gtk_text_iter_backward_visible_word_starts (&mv.insert, MAX (1, mv.count));
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_SUB_WORD_START:
      if (!gtk_text_iter_forward_visible_word_ends (&mv.insert, MAX (1, mv.count)))
        gtk_text_iter_forward_to_line_end (&mv.insert);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_word_start (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_START:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_word_start (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_END:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_word_end (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_WORD_END:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_word_end (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SENTENCE_START:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_sentence_start (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SENTENCE_END:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_sentence_end (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_START:
      for (i = MAX (1, mv.count); i > 0; i--)
        {
          mv.exclusive = exclusive && i == 1;
          ide_source_view_movements_paragraph_start (&mv);
        }
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PARAGRAPH_END:
      for (i = MAX (1, mv.count); i > 0; i--)
        {
          mv.exclusive = exclusive && i == 1;
          ide_source_view_movements_paragraph_end (&mv);
        }
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_LINE:
      mv.ignore_target_offset = TRUE;
      mv.ignore_select = TRUE;
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_line (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_LINE:
      mv.ignore_target_offset = TRUE;
      mv.ignore_select = TRUE;
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_line (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_FIRST_LINE:
      ide_source_view_movements_first_line (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE:
      ide_source_view_movements_nth_line (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_LAST_LINE:
      ide_source_view_movements_last_line (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_LINE_PERCENTAGE:
      ide_source_view_movements_line_percentage (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_LINE_CHARS:
      ide_source_view_movements_line_chars (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_LINE_END:
      ide_source_view_movements_line_end (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_UP:
    case IDE_SOURCE_VIEW_MOVEMENT_HALF_PAGE_DOWN:
    case IDE_SOURCE_VIEW_MOVEMENT_PAGE_UP:
    case IDE_SOURCE_VIEW_MOVEMENT_PAGE_DOWN:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_move_page (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_DOWN:
    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_UP:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_scroll (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_TOP:
      ide_source_view_movements_screen_top (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_MIDDLE:
      ide_source_view_movements_screen_middle (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SCREEN_BOTTOM:
      ide_source_view_movements_screen_bottom (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_MATCH_SPECIAL:
      ide_source_view_movements_match_special (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_TOP:
    case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_CENTER:
    case IDE_SOURCE_VIEW_MOVEMENT_SCROLL_SCREEN_BOTTOM:
      ide_source_view_movements_scroll_center (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_UNMATCHED_BRACE:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_unmatched (&mv, '{', '}');
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_UNMATCHED_BRACE:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_unmatched (&mv, '}', '{');
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_UNMATCHED_PAREN:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_unmatched (&mv, '(', ')');
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_UNMATCHED_PAREN:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_unmatched (&mv, ')', '(');
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_MATCH_MODIFIER:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_next_match_modifier (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_MATCH_MODIFIER:
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movements_previous_match_modifier (&mv);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_MATCH_SEARCH_CHAR:
      mv.modifier = search_char;
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movement_match_search_char (&mv, FALSE);
      break;

    case IDE_SOURCE_VIEW_MOVEMENT_NEXT_MATCH_SEARCH_CHAR:
      mv.modifier = search_char;
      for (i = MAX (1, mv.count); i > 0; i--)
        ide_source_view_movement_match_search_char (&mv, TRUE);
      break;

    default:
      g_return_if_reached ();
    }

  if (!mv.ignore_select)
    ide_source_view_movements_select_range (&mv);

  if (!mv.ignore_target_offset)
    *target_offset = gtk_text_iter_get_line_offset (&mv.insert);

  if (!mv.ignore_scroll_to_insert)
    ide_source_view_scroll_mark_onscreen (self, insert, TRUE, 0.5, 0.5);
}
Esempio n. 11
0
static int
delete_selection_in_gtk_text_view(GtkTextView *text_view,
				  enum UTextOrigin origin, int former_req_len,
				  int latter_req_len)
{
  GtkTextIter current, start, end, tmp_start, tmp_end;
  gboolean cursor_at_beginning = FALSE;

  if (!gtk_text_view_get_buffer(text_view))
    return -1;

  if (gtk_text_buffer_get_selection_bounds(gtk_text_view_get_buffer(text_view),
      &start, &end)) {
    gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(text_view),
        &current,
        gtk_text_buffer_get_mark(gtk_text_view_get_buffer(text_view),
        "insert"));
    if (gtk_text_iter_compare(&start, &current) == 0)
      cursor_at_beginning = TRUE;
  } else {
    return -1;
  }

  if (origin == UTextOrigin_Beginning ||
      (origin == UTextOrigin_Cursor && cursor_at_beginning)) {
    tmp_start = start;
    tmp_end = start;

    if (latter_req_len >= 0) {
      gtk_text_iter_forward_chars(&tmp_end, latter_req_len);
      if (gtk_text_iter_compare(&tmp_end, &end) < 0)
	end = tmp_end;
    } else {
      if (latter_req_len == UTextExtent_Line) {
	gtk_text_view_forward_display_line_end(text_view, &tmp_end);
	if (gtk_text_iter_compare(&tmp_end, &end) < 0)
	  end = tmp_end;
      } else {
	if (!(latter_req_len == UTextExtent_Full))
	  return -1;
      }
    }

  } else if (origin == UTextOrigin_End ||
	     (origin == UTextOrigin_Cursor && !cursor_at_beginning)) {
    tmp_start = end;
    tmp_end = end;

    if (former_req_len >= 0) {
      gtk_text_iter_backward_chars(&tmp_start, former_req_len);
      if (gtk_text_iter_compare(&tmp_start, &start) > 0)
	start = tmp_start;
    } else {
      if (former_req_len == UTextExtent_Line) {
	gtk_text_view_backward_display_line_start(text_view, &tmp_start);
	if (gtk_text_iter_compare(&tmp_start, &start) > 0)
	  start = tmp_start;
      } else {
	if (!(former_req_len == UTextExtent_Full))
	  return -1;
      }
    }

  } else {
    return -1;
  }

  gtk_text_buffer_delete_interactive(gtk_text_view_get_buffer(text_view),
      &start, &end, gtk_text_view_get_editable(text_view));

  return 0;
}
Esempio n. 12
0
static int
delete_text_in_gtk_text_view(GtkTextView *text_view, enum UTextOrigin origin,
			     int former_req_len, int latter_req_len)
{
  GtkTextIter current, start, end;

  if (!gtk_text_view_get_buffer(text_view))
    return -1;

  gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(text_view),
      &current,
      gtk_text_buffer_get_mark(gtk_text_view_get_buffer(text_view), "insert"));
  start = current;
  end = current;

  switch (origin) {
  case UTextOrigin_Cursor:
    if (former_req_len >= 0) {
      gtk_text_iter_backward_chars(&start, former_req_len);
    } else {
      if (former_req_len == UTextExtent_Full)
	gtk_text_buffer_get_start_iter(gtk_text_view_get_buffer(text_view), &start);
      else if (former_req_len == UTextExtent_Line)
	gtk_text_view_backward_display_line_start(text_view, &start);
      else
	return -1;
    }

    if (latter_req_len >= 0)
      gtk_text_iter_forward_chars(&end, latter_req_len);
    else {
      if (latter_req_len == UTextExtent_Full)
	gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(text_view), &end);
      else if (latter_req_len == UTextExtent_Line)
	gtk_text_view_forward_display_line_end(text_view, &end);
      else
	return -1;
    }
    break;

  case UTextOrigin_Beginning:
    gtk_text_buffer_get_start_iter(gtk_text_view_get_buffer(text_view), &start);
    end = start;

    if (latter_req_len >= 0)
      gtk_text_iter_forward_chars(&end, latter_req_len);
    else {
      if (latter_req_len == UTextExtent_Full)
	gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(text_view), &end);
      else if (latter_req_len == UTextExtent_Line)
	gtk_text_view_forward_display_line_end(text_view, &end);
      else
	return -1;
    }
    break;

  case UTextOrigin_End:
    gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(text_view), &end);
    start = end;

    if (former_req_len >= 0) {
      gtk_text_iter_backward_chars(&start, former_req_len);
    } else {
      if (former_req_len == UTextExtent_Full)
	gtk_text_buffer_get_start_iter(gtk_text_view_get_buffer(text_view), &start);
      else if (former_req_len == UTextExtent_Line)
	gtk_text_view_backward_display_line_start(text_view, &start);
      else
	return -1;
    }
    break;

  case UTextOrigin_Unspecified:
  default:
    return -1;
  }

  gtk_text_buffer_delete_interactive(gtk_text_view_get_buffer(text_view),
      &start, &end, gtk_text_view_get_editable(text_view));

  return 0;
}
Esempio n. 13
0
static int
acquire_text_in_gtk_text_view(GtkTextView *text_view, enum UTextOrigin origin,
			      int former_req_len, int latter_req_len,
			      char **former, char **latter)
{
  GtkTextIter current, start, end;

  if (!gtk_text_view_get_buffer(text_view))
    return -1;

  gtk_text_buffer_get_iter_at_mark(gtk_text_view_get_buffer(text_view),
      &current,
      gtk_text_buffer_get_mark(gtk_text_view_get_buffer(text_view), "insert"));
  switch (origin) {
  case UTextOrigin_Cursor:
    start = current;
    end = current;

    if (former_req_len >= 0) {
      gtk_text_iter_backward_chars(&start, former_req_len);
    } else {
      if (former_req_len == UTextExtent_Full)
	gtk_text_buffer_get_start_iter(gtk_text_view_get_buffer(text_view), &start);
      else if (former_req_len == UTextExtent_Line)
	gtk_text_view_backward_display_line_start(text_view, &start);
      else
	return -1;
    }
    *former = gtk_text_iter_get_slice(&start, &current);

    if (latter_req_len >= 0)
      gtk_text_iter_forward_chars(&end, latter_req_len);
    else {
      if (latter_req_len == UTextExtent_Full)
	gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(text_view), &end);
      else if (latter_req_len == UTextExtent_Line)
	gtk_text_view_forward_display_line_end(text_view, &end);
      else {
	g_free(*former);
	return -1;
      }
    }
    *latter = gtk_text_iter_get_slice(&current, &end);
    break;

  case UTextOrigin_Beginning:
    gtk_text_buffer_get_start_iter(gtk_text_view_get_buffer(text_view), &start);
    end = start;

    *former = NULL;

    if (latter_req_len >= 0)
      gtk_text_iter_forward_chars(&end, latter_req_len);
    else {
      if (latter_req_len == UTextExtent_Full)
	gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(text_view), &end);
      else if (latter_req_len == UTextExtent_Line)
	gtk_text_view_forward_display_line_end(text_view, &end);
      else
        return -1;
    }
    *latter = gtk_text_iter_get_slice(&start, &end);
    break;

  case UTextOrigin_End:
    gtk_text_buffer_get_end_iter(gtk_text_view_get_buffer(text_view), &end);
    start = end;

    if (former_req_len >= 0) {
      gtk_text_iter_backward_chars(&start, former_req_len);
    } else {
      if (former_req_len == UTextExtent_Full)
	gtk_text_buffer_get_start_iter(gtk_text_view_get_buffer(text_view), &start);
      else if (former_req_len == UTextExtent_Line)
	gtk_text_view_backward_display_line_start(text_view, &start);
      else
	return -1;
    }
    *former = gtk_text_iter_get_slice(&start, &end);

    *latter = NULL;
    break;

  case UTextOrigin_Unspecified:
  default:
    return -1;
  }

  return 0;
}