Exemplo n.º 1
0
void snippets_activate (GuSnippets* sc, GuEditor* ec, gchar* key) {
    gchar* snippet = NULL;
    GuSnippetInfo* new_info = NULL;
    GtkTextIter start, end;

    slog (L_DEBUG, "Snippet `%s' activated\n", key);

    snippet = snippets_get_value (sc, key);
    g_return_if_fail (snippet != NULL);

    new_info = snippets_parse (snippet);

    gtk_text_buffer_get_selection_bounds (ec_buffer, &start, &end);
    new_info->start_offset = gtk_text_iter_get_offset (&start);
    new_info->sel_text = gtk_text_iter_get_text (&start, &end);
    GSList* marks = gtk_text_iter_get_marks (&start);
    new_info->sel_start = *GTK_TEXT_MARK (marks->data);
    g_slist_free (marks);

    gtk_text_buffer_insert (ec_buffer, &start, new_info->expanded, -1);
    snippet_info_create_marks (new_info, ec);
    snippet_info_initial_expand (new_info, ec);
    gtk_text_buffer_set_modified (ec_buffer, TRUE);

    if (sc->info) {
        snippet_info_sync_group (sc->info, ec);
        sc->stackframe = g_list_append (sc->stackframe, sc->info);
    }
    sc->info = new_info;

    if (!snippet_info_goto_next_placeholder (sc->info, ec))
        snippets_deactivate (sc, ec);
}
Exemplo n.º 2
0
/**
  Kolorowanie słów.
  Słowa nie znajdujące się w słowniku - potencjalnie błędne - zostają
  oznaczone na czerwono.
  */
static void show_errors() {
  GtkTextIter start, end, text_end;
  int i, range;
  char *word;
  gunichar *wword;

  gtk_text_buffer_create_tag(editor_buf, "red_fg", 
                             "foreground", "red", 
                             "weight", PANGO_WEIGHT_BOLD, NULL);
  gtk_text_buffer_get_end_iter(editor_buf, &text_end);
  gtk_text_buffer_get_start_iter(editor_buf, &end);
  range = gtk_text_buffer_get_char_count(editor_buf);
  while (!gtk_text_iter_is_end(&end)) {
    gtk_text_iter_forward_word_end(&end); 
    start = end;
    gtk_text_iter_backward_word_start(&start); 

    word = gtk_text_iter_get_text(&start, &end);
    wword = g_utf8_to_ucs4_fast(word, -1, NULL);
    if (make_lowercase(wword)) {
      if (!dictionary_find(dict, wword))
      gtk_text_buffer_apply_tag_by_name(editor_buf, "red_fg", 
                                      &start, &end);
    }
    g_free(word);
    g_free(wword);
  }

}
Exemplo n.º 3
0
Arquivo: text.c Projeto: polarcat/yad
static gboolean
tag_event_cb (GtkTextTag *tag, GObject *obj, GdkEvent *ev,
	      GtkTextIter *iter, gpointer d)
{
  GtkTextIter start = *iter;
  GtkTextIter end = *iter;
  gchar *url, *cmdline;

  if (ev->type == GDK_BUTTON_PRESS)
    {
      GdkEventButton *bev = (GdkEventButton *) ev;

      if (bev->button == 1)
        {
          gtk_text_iter_backward_to_tag_toggle (&start, tag);
          gtk_text_iter_forward_to_tag_toggle (&end, tag);

          url = gtk_text_iter_get_text (&start, &end);
          cmdline = g_strdup_printf ("xdg-open '%s'", url);
          g_free (url);

          g_spawn_command_line_async (cmdline, NULL);

          g_free (cmdline);
	  return TRUE;
        }
    }

  return FALSE;
}
static gchar *
get_word (GtkSourceCompletionProvider *provider,
          GtkTextIter                 *iter)
{
   GtkTextIter *end;
   gboolean moved = FALSE;
   gunichar c;
   gchar *word;

   end = gtk_text_iter_copy(iter);

   do {
      if (!gtk_text_iter_backward_char(iter)) {
         break;
      }
      c = gtk_text_iter_get_char(iter);
      moved = TRUE;
   } while (!is_stop_char(c));

   if (moved && !gtk_text_iter_is_start(iter)) {
      gtk_text_iter_forward_char(iter);
   }

   word = g_strstrip(gtk_text_iter_get_text(iter, end));

   gtk_text_iter_free(end);

   return word;
}
void
apotheke_highlight_buffer_diff (GtkTextBuffer *buffer, GtkTextIter *start)
{
	GtkTextIter *end;
	GtkTextIter *word_end;
	gchar *c;

	if (!gtk_text_iter_starts_line (start))
		gtk_text_iter_set_line_offset (start, 0);


	while (!gtk_text_iter_is_end (start)) {
		end = gtk_text_iter_copy (start);
		if (!gtk_text_iter_forward_to_line_end (end))
			break;

		word_end = gtk_text_iter_copy (start);
		gtk_text_iter_forward_char (word_end);
		
		c = gtk_text_iter_get_text (start, word_end);
		if (g_ascii_strcasecmp ("+", c) == 0) {
			gtk_text_buffer_apply_tag_by_name (buffer,
							   "diff-added",
							   start, end);
		} 
		else if (g_ascii_strcasecmp ("-", c) == 0) {
			gtk_text_buffer_apply_tag_by_name (buffer,
							   "diff-removed",
							   start, end);
		}

		gtk_text_iter_forward_line (start);
	}
}
Exemplo n.º 6
0
Arquivo: about.c Projeto: Mortal/claws
static gboolean about_textview_uri_clicked(GtkTextTag *tag, GObject *obj,
					GdkEvent *event, GtkTextIter *iter,
					GtkWidget *textview)
{
	GtkTextIter start_iter, end_iter;
	GdkEventButton *bevent;
	gchar *link = NULL;

	if (!event || !tag) {
		return FALSE;
	}

	if (event->type != GDK_BUTTON_PRESS && event->type != GDK_2BUTTON_PRESS
		&& event->type != GDK_BUTTON_RELEASE) {
		return FALSE;
	}

	/* get link text from tag */
	if (get_tag_range(iter, tag, &start_iter,
				   &end_iter) == FALSE) {
		return FALSE;
	}
	link = gtk_text_iter_get_text(&start_iter, &end_iter);
	if (link == NULL) {
		return FALSE;
	}

	bevent = (GdkEventButton *) event;
	if (bevent->button == 1 && event->type == GDK_BUTTON_RELEASE) {
		GtkTextBuffer *buffer;

		/* we shouldn't follow a link if the user has selected something */
		buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
		gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter);
		if (gtk_text_iter_get_offset(&start_iter) != gtk_text_iter_get_offset(&end_iter)) {
			return FALSE;
		}
		/* open link and do *not* return TRUE so that
		   further gtk processing of the signal is done */
		open_uri(link, prefs_common_get_uri_cmd());

	} else {
		if (bevent->button == 3 && event->type == GDK_BUTTON_PRESS) {
			link_popupmenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
				gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TextviewPopupLink")));

			g_object_set_data(
					G_OBJECT(link_popupmenu),
					"raw_url", link);
			gtk_menu_popup(GTK_MENU(link_popupmenu), 
					NULL, NULL, NULL, NULL, 
					bevent->button, bevent->time);

			return TRUE;
		}
	}
	return FALSE;
}
ustring CheckCapitalization::get_context(GtkTextIter iter)
// Returns the context at iter: A couple of words before and after.
{
  GtkTextIter iter1 = iter;
  GtkTextIter iter2 = iter;
  gtk_text_iter_backward_word_starts(&iter1, 2);
  gtk_text_iter_forward_word_ends(&iter2, 2);
  return gtk_text_iter_get_text(&iter1, &iter2);
}
Exemplo n.º 8
0
void Highlight::searchwords_in_area(GtkTextBuffer * textbuffer, vector < GtkTextIter > &start, vector < GtkTextIter > &end, bool area_id, bool area_intro, bool area_heading, bool area_chapter, bool area_study, bool area_notes, bool area_xref, bool area_verse)
/*
Finds out whether the text within the "start" and "end" iterators is inside
one of the given areas. If not, it removes the iterator from the containers.
*/
{
  // Categorization data
  CategorizeLine categorize("");
  // Go through the iterators, starting at the end (to make erasing it easier).
  for (int it = start.size() - 1; it >= 0; it--) {
    // Get line number of the iterator.
    gint linenumber = gtk_text_iter_get_line(&start[it]);
    // Get the usfm this line starts with.
    ustring usfm;
    {
      GtkTextIter line1;
      gtk_text_buffer_get_iter_at_line(textbuffer, &line1, linenumber);
      GtkTextIter line2 = line1;
      gtk_text_iter_forward_chars(&line2, 10);
      ustring line = gtk_text_iter_get_text(&line1, &line2);
      usfm = usfm_extract_marker(line);
    }
    // See if this usfm is in one of the areas given.
    bool in_area = false;
    if (area_id)
      if (categorize.is_id_marker(usfm))
        in_area = true;
    if (area_intro)
      if (categorize.is_intro_marker(usfm))
        in_area = true;
    if (area_heading)
      if (categorize.is_head_marker(usfm))
        in_area = true;
    if (area_chapter)
      if (categorize.is_chap_marker(usfm))
        in_area = true;
    if (area_study)
      if (categorize.is_study_marker(usfm))
        in_area = true;
    // The variables "area_notes" and "area_xref" are not relevant.
    if (area_verse)
      if (categorize.is_verse_marker(usfm))
        in_area = true;
    // If not in one of the areas, remove this iterator from the container.
    if (!in_area) {
      vector < GtkTextIter >::iterator startiter = start.begin();
      vector < GtkTextIter >::iterator enditer = end.begin();
      for (int i = 0; i < it; i++) {
        startiter++;
        enditer++;
      }
      start.erase(startiter);
      end.erase(enditer);
    }
  }
}
/**
 * gsc_utils_get_word_iter:
 *
 * @text_buffer: The #GtkTextBuffer
 * @start_word: if != NULL then assign it the start position of the word
 * @end_word: if != NULL then assing it the end position of the word
 *
 * Returns: the current word
 *
 */
gchar *
gsc_utils_get_word_iter (GtkTextBuffer *text_buffer,
                         GtkTextIter     *current,
                         GtkTextIter     *start_word,
                         GtkTextIter     *end_word)
{
    gunichar ch;
    gboolean no_doc_start;

    if (current == NULL)
    {
        gtk_text_buffer_get_iter_at_mark (text_buffer,
                                          start_word,
                                          gtk_text_buffer_get_insert (text_buffer));
    }
    else
    {
        *start_word = *current;
    }

    *end_word = *start_word;

    while ((no_doc_start = gtk_text_iter_backward_char (start_word)) == TRUE)
    {
        ch = gtk_text_iter_get_char (start_word);

        if (gsc_utils_is_separator (ch))
        {
            break;
        }
    }

    if (!no_doc_start)
    {
        gtk_text_buffer_get_start_iter (text_buffer, start_word);
        return gtk_text_iter_get_text (start_word, end_word);
    }
    else
    {
        gtk_text_iter_forward_char (start_word);
        return gtk_text_iter_get_text (start_word, end_word);
    }
}
Exemplo n.º 10
0
static gchar *compute_indentation(GtkTextBuffer *buffer, GtkTextIter *iter, gint line)
{
	GtkTextIter start_iter, end_iter;
	gunichar ch;
	
	gtk_text_buffer_get_iter_at_line(buffer, &start_iter, line);
	end_iter = start_iter;
	ch = gtk_text_iter_get_char(&end_iter);
	while (g_unichar_isspace(ch) && ch != '\n') {
		if (!gtk_text_iter_forward_char(&end_iter))
			break;
		ch = gtk_text_iter_get_char(&end_iter);
	}
	if (gtk_text_iter_equal(&start_iter, &end_iter))
		return NULL;
	
	if (iter && gtk_text_iter_compare(iter, &end_iter) < 0)
		return gtk_text_iter_get_text(&start_iter, iter);
	return gtk_text_iter_get_text(&start_iter, &end_iter);
}
Exemplo n.º 11
0
static void
text_buffer_undo_delete_range_cb (GtkTextBuffer *text_buffer,
                                  GtkTextIter *start,
                                  GtkTextIter *end,
                                  gpointer user_data)
{
	push_delete_undo (
		G_OBJECT (text_buffer),
		gtk_text_iter_get_text (start, end),
		gtk_text_iter_get_offset (start),
		gtk_text_iter_get_offset (end));
}
Exemplo n.º 12
0
/**
 * bmark_text_for_offset:
 *
 * will use offset if itoffset is NULL
 * will use itoffset if not NULL
 */
static gchar *bmark_text_for_offset(Tdocument *doc, GtkTextIter *itoffset, gint offset) {
	GtkTextIter it, eit, sit;
	if (itoffset) {
		it = *itoffset;
	} else {
		gtk_text_buffer_get_iter_at_offset(doc->buffer,&it,offset);
	}
	sit = eit = it;
	gtk_text_iter_forward_to_line_end(&eit);
	gtk_text_iter_forward_chars(&sit, BMARK_SHOW_NUM_TEXT_CHARS);
	if (!gtk_text_iter_in_range(&sit, &it, &eit))
		sit = eit;
#ifdef DEBUG
	{
		gchar *tmp = gtk_text_iter_get_text(&it, &sit);
		DEBUG_MSG("bmark_text_for_offset, text=%s\n",tmp);
		g_free(tmp);
	}
#endif
	return gtk_text_iter_get_text(&it, &sit);
}
Exemplo n.º 13
0
static gchar *
get_word_at_iter (GscProviderDevhelp *devhelp,
                  GtkTextIter        *iter)
{
	GtkTextIter start = *iter;
	gint line = gtk_text_iter_get_line (iter);
	gboolean went_back = TRUE;
	GtkTextMark *mark;
	
	if (!gtk_text_iter_backward_char (&start))
	{
		return NULL;
	}

	while (went_back &&
	       line == gtk_text_iter_get_line (&start) && 
	       is_word_char (gtk_text_iter_get_char (&start)))
	{
		went_back = gtk_text_iter_backward_char (&start);
	}
	
	if (went_back)
	{
		gtk_text_iter_forward_char (&start);
	}
	
	if (gtk_text_iter_equal (iter, &start))
	{
		return NULL;
	}

	mark = gtk_text_buffer_get_mark (gtk_text_iter_get_buffer (iter),
					 MARK_NAME);
	
	if (mark)
	{
		gtk_text_buffer_move_mark (gtk_text_iter_get_buffer (iter),
		                           mark,
		                           &start);
	}
	else
	{
		mark = gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (iter),
		                                    MARK_NAME,
		                                    &start,
		                                    TRUE);
	}
	
	return gtk_text_iter_get_text (&start, iter);
}
Exemplo n.º 14
0
//================================================================
  int GUI_edi_Rd2it (char* txbuf, long txlen,
                     GtkTextIter *it1, GtkTextIter *it2) {
//================================================================
/// \code
/// get text between 2 iters INTERNAL
/// p1, p2  character-offset, not byte offsets !
/// get whole window with: p1=0L, p2=-1L
/// Input:
///   txlen         size of txbuf
/// \endcode


  char        *text;
  long        sSiz;


  // printf("GUI_edi_Rd2it %ld\n",txlen);

  // get textPointer;
  text = gtk_text_iter_get_text (it1, it2);
  if(!text) {  // 2013-12-29
    TX_Error("GUI_edi_Rd2it E001");
    return -1;
  }


  sSiz = strlen(text);   // g_utf8_strlen
    // printf(" sSiz=%ld\n",sSiz);


  if(sSiz < txlen) {
    // remove '\n'
    // if(text[sSiz - 1] == '\n') --sSiz;  // 2012-11-18 removed
    // copy out
    strncpy(txbuf, text, sSiz);
    txbuf[sSiz] = '\0';

  } else {
    sSiz = -1;
  }

  g_free (text);

  // printf("ex GUI_edi_Rd2it %ld\n",sSiz);
  // printf("|"); UTX_dump_s__(txbuf,*txlen+1);printf("|");

  return sSiz;

}
Exemplo n.º 15
0
static gboolean check_selection_bound(GtkTextBuffer *buffer)
{
	GtkTextIter start, end;
	gchar *str, *p;
	
	if (gtk_text_buffer_get_selection_bounds(buffer, &start, &end)) {
		str = gtk_text_iter_get_text(&start, &end);
		p = strchr(str, '\n');
		g_free(str);
		if (p)
			return TRUE;
	}
	
	return FALSE;
}
Exemplo n.º 16
0
gboolean snippets_key_press_cb (GuSnippets* sc, GuEditor* ec, GdkEventKey* ev) {
    GtkTextIter current, start;

    if (ev->keyval == GDK_KEY_Tab) {
        gchar* key = NULL;
        editor_get_current_iter (ec, &current);
        if (gtk_text_iter_ends_word (&current)) {
            start = current;
            gtk_text_iter_backward_word_start (&start);
            key = gtk_text_iter_get_text (&start, &current);

            if (snippets_get_value (sc, key)) {
                gtk_text_buffer_delete (ec_buffer, &start, &current);
                snippets_activate (sc, ec, key);
                g_free (key);
                return TRUE;
            }
            g_free (key);
        }
    }
    
    if (sc->info) {
        if (ev->keyval == GDK_KEY_Tab) {
            if (!snippet_info_goto_next_placeholder (sc->info, ec))
                snippets_deactivate (sc, ec);
            return TRUE;
        } else if (ev->keyval == GDK_KEY_ISO_Left_Tab
                   && ev->state & GDK_SHIFT_MASK) {
            if (!snippet_info_goto_prev_placeholder (sc->info, ec))
                snippets_deactivate (sc, ec);
            return TRUE;
        }
        /* Deactivate snippet if the current insert range is not within the
         * snippet */
        editor_get_current_iter (ec, &current);
        gint offset = gtk_text_iter_get_offset (&current);
        GList* last = g_list_last (sc->info->einfo);
        if (last) {
            gtk_text_buffer_get_iter_at_mark (ec_buffer, &current,
                    GU_SNIPPET_EXPAND_INFO (last->data)->left_mark);
            gint bound_end = gtk_text_iter_get_offset (&current);
            if (offset < sc->info->start_offset || offset > bound_end)
                snippets_deactivate (sc, ec);
        }
    }

    return FALSE;
}
Exemplo n.º 17
0
/* While not as cool as c-mode, this will do as a quick attempt at highlighting */
static void
fontify (GtkTextBuffer *source_buffer)
{
  GtkTextIter start_iter, next_iter, tmp_iter;
  gint state;
  gchar *text;
  gchar *start_ptr, *end_ptr;
  gchar *tag;

  gtk_text_buffer_get_bounds (source_buffer, &start_iter, &tmp_iter);
  gtk_text_buffer_apply_tag_by_name (source_buffer, "source", &start_iter, &tmp_iter);

  state = STATE_NORMAL;

  gtk_text_buffer_get_iter_at_offset (source_buffer, &start_iter, 0);

  next_iter = start_iter;
  while (gtk_text_iter_forward_line (&next_iter))
    {
      gboolean start = TRUE;
      start_ptr = text = gtk_text_iter_get_text (&start_iter, &next_iter);

      do
        {
          parse_chars (start_ptr, &end_ptr, &state, &tag, start);

          start = FALSE;
          if (end_ptr)
            {
              tmp_iter = start_iter;
              gtk_text_iter_forward_chars (&tmp_iter, end_ptr - start_ptr);
            }
          else
            {
              tmp_iter = next_iter;
            }
          if (tag)
            gtk_text_buffer_apply_tag_by_name (source_buffer, tag, &start_iter, &tmp_iter);

          start_iter = tmp_iter;
          start_ptr = end_ptr;
        }
      while (end_ptr);

      g_free (text);
      start_iter = next_iter;
    }
}
static void
directions_buffer_changed (GtkTextBuffer *textbuffer,
                           gpointer       user_data)
{
	GPInstructLessonTestMultiChoiceEditor *editor = GPINSTRUCT_LESSON_TEST_MULTI_CHOICE_EDITOR (user_data);
	GPInstructLessonTestMultiChoiceEditorPrivate *priv = editor->priv;

	GtkTextIter start, end;
	gchar *text;
	gtk_text_buffer_get_bounds (textbuffer, &start, &end);
	text = gtk_text_iter_get_text (&start, &end);
	gpinstruct_lesson_test_set_directions (GPINSTRUCT_LESSON_TEST (priv->test),
	                                       text);
	g_free (text);
	gpinstruct_editor_window_set_modified (priv->window, TRUE);
}
Exemplo n.º 19
0
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);
}
Exemplo n.º 20
0
/* TODO: Move to ConboyNoteBuffer
 * The return value needs to be freed by the caller.
 */
gchar* note_extract_title_from_buffer(GtkTextBuffer *buffer)
{
	GtkTextIter start, end;
	gchar* title;

	/* Set end iter depending on if we have one or more lines */
	if (gtk_text_buffer_get_line_count(buffer) == 1) {
		gtk_text_buffer_get_end_iter(buffer, &end);
	} else {
		gtk_text_buffer_get_iter_at_line(buffer, &end, 1);
		gtk_text_iter_backward_char(&end);
	}

	gtk_text_buffer_get_start_iter(buffer, &start);
	title = gtk_text_iter_get_text(&start, &end);
	return title;
}
Exemplo n.º 21
0
//================================================================
  int GUI_edi_sel_wrf (MemObj *mo, char *fnam) {
//================================================================
/// \code
/// GUI_edi_sel_wrf              write selected -> file
/// returns nr of chars
/// \endcode

  GtkTextIter it1, it2;
  int  i1;
  char *text;
  FILE *fpo;


  // printf("GUI_Ed_sel_wrf |%s|\n",fnam);

  if((fpo=fopen(fnam,"wb")) == NULL) {
    TX_Print("GUI_Ed_sel_wrf E001 |%s|",fnam);
    return -2;
  }


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


  // get get iters for "insert" & "selection_bound"
  gtk_text_buffer_get_selection_bounds (GUI_ed1_buff, &it1, &it2);

  // get text
  text = gtk_text_iter_get_text (&it1, &it2);
    // printf("/%s/\n",text);

  i1 = strlen(text);

  fwrite(text, i1, 1, fpo);

  g_free (text);

  fclose(fpo);

  return i1;

}
Exemplo n.º 22
0
static gchar *
get_url_at_iter (GtkTextBuffer *buffer,
                 GtkTextIter *iter)
{
	GtkTextTagTable *tag_table;
	GtkTextTag *tag;
	GtkTextIter start, end;
	gchar *url = NULL;

	g_return_val_if_fail (buffer != NULL, NULL);

	tag_table = gtk_text_buffer_get_tag_table (buffer);
	tag = gtk_text_tag_table_lookup (tag_table, E_BUFFER_TAGGER_LINK_TAG);
	g_return_val_if_fail (tag != NULL, NULL);

	if (get_tag_bounds (iter, tag, &start, &end))
		url = gtk_text_iter_get_text (&start, &end);

	return url;
}
Exemplo n.º 23
0
// Koloruje słowa nie ze słownika na czerwono
static void ColorMistakes (GtkMenuItem *item, gpointer data) {
  GtkTextIter start, end, buffEnd;

  gtk_text_buffer_get_start_iter(editor_buf, &end);

  //Teraz sztuczką przesuwamy końcowy iterator na koniec ostatniego słowa
  gtk_text_buffer_get_end_iter(editor_buf, &buffEnd);
  gtk_text_iter_backward_word_start(&buffEnd);
  gtk_text_iter_forward_word_end(&buffEnd);

  gtk_text_buffer_create_tag(editor_buf, "red_fg", 
                             "foreground", "red", 
                             "weight", PANGO_WEIGHT_BOLD, NULL);

  // Aktualizacja słownika
  if(update_actual_dict() < 0)
    return;
  start = end;

  while (!gtk_text_iter_equal(&end, &buffEnd)) {
    // Inkrementacja zmiennych
		gtk_text_iter_forward_word_end(&end); 
		start = end;
		gtk_text_iter_backward_word_start(&start);

    // Usuwamy etykietkę ze słowa jeśli jest
    gtk_text_buffer_remove_tag_by_name(editor_buf, "red_fg", 
                                      &start, &end);

    // Separujemy słowo
    char* word = gtk_text_iter_get_text(&start, &end);
    gunichar* wword = g_utf8_to_ucs4_fast(word, -1, NULL);

    // Jeśli znaleziono w słowniku to kolorujemy
    if(!dictionary_find(dict, (const wchar_t*)wword))
      gtk_text_buffer_apply_tag_by_name(editor_buf, "red_fg", 
                                        &start, &end);
    g_free(word);

  }
}
Exemplo n.º 24
0
void insert_open_brace(GtkWidget **tip_win, GtkWidget *text_view, GtkTextIter *arg1)
{
	GdkWindow *win;
	GtkTextIter start;
	GdkRectangle buf_loc;
	gint x, y;
	gint win_x, win_y;
	gchar *text;
	gchar *tip_text;

	start = *arg1;
	if (!gtk_text_iter_backward_word_start (&start))
		return;
	text = gtk_text_iter_get_text (&start, arg1);
	g_strstrip (text);

	tip_text = get_tip(text);  
	if (tip_text == NULL)
		return;

	gtk_text_view_get_iter_location (GTK_TEXT_VIEW (text_view), arg1, &buf_loc);
	g_printf ("Buffer: %d, %d\n", buf_loc.x, buf_loc.y);
	gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (text_view),
	GTK_TEXT_WINDOW_WIDGET,
	buf_loc.x, buf_loc.y,
	&win_x, &win_y);
	g_printf ("Window: %d, %d\n", win_x, win_y);
	win = gtk_text_view_get_window (GTK_TEXT_VIEW (text_view), 
	GTK_TEXT_WINDOW_WIDGET);
	gdk_window_get_origin (win, &x, &y);

	if (*tip_win != NULL)
		gtk_widget_destroy (GTK_WIDGET (*tip_win));  

	*tip_win = tip_window_new (tip_text);
	g_free(tip_text);
	gtk_window_move (GTK_WINDOW (*tip_win), win_x + x, 
	win_y + y + buf_loc.height);
	gtk_widget_show_all (*tip_win);
}
Exemplo n.º 25
0
gboolean search_tools_active_search_entry(GtkWidget* widget, GdkEventFocus* event, SearchTools* self) {
	GtkTextBuffer* buf;
	gint page_num;

	page_num = gtk_notebook_get_current_page(puss_get_doc_panel(self->app));
	if( page_num >= 0 ) {
		buf = self->app->doc_get_buffer_from_page_num(page_num);
		if( buf ) {
			GtkTextIter ps, pe;
			if( gtk_text_buffer_get_selection_bounds(buf, &ps, &pe) ) {
				gchar* text = gtk_text_iter_get_text(&ps, &pe);
				if( text ) {
					gtk_entry_set_text(self->search_entry, text);
					g_free(text);
				}
			}
		}
	}

	gtk_widget_grab_focus(GTK_WIDGET(self->search_entry));
	return TRUE;
}
Exemplo n.º 26
0
ParseWords::ParseWords(const ustring & text)
// Parses a line of text in its separate words.
// Note: This is comparable to object Parse, but does a better job.
{
  // Load text into buffer.
  ustring text2(text);
  text2.append(" ");
  GtkTextBuffer *textbuffer;
  textbuffer = gtk_text_buffer_new(NULL);
  gtk_text_buffer_set_text(textbuffer, text2.c_str(), -1);
  // Iterators.  
  GtkTextIter startiter, enditer;
  // Parse into separate words.
  gtk_text_buffer_get_start_iter(textbuffer, &enditer);
  while (gtk_text_iter_forward_word_end(&enditer)) {
    startiter = enditer;
    gtk_text_iter_backward_word_start(&startiter);
    ustring word = gtk_text_iter_get_text(&startiter, &enditer);
    words.push_back(word);
  }
  // Free memory
  g_object_unref(textbuffer);
}
Exemplo n.º 27
0
ustring CheckMatchingPairs::get_context(ustring & line, unsigned int offset)
// Returns the context at offset: A couple of words before and after.
{
  // Result.
  ustring returnvalue;
  // Load text into buffer.
  GtkTextBuffer *textbuffer;
  textbuffer = gtk_text_buffer_new(NULL);
  gtk_text_buffer_set_text(textbuffer, line.c_str(), -1);
  // Iterators.  
  GtkTextIter iter1;
  GtkTextIter iter2;
  // Find boundaries of context to return.
  gtk_text_buffer_get_iter_at_offset(textbuffer, &iter1, offset);
  iter2 = iter1;
  gtk_text_iter_backward_word_starts(&iter1, 2);
  gtk_text_iter_forward_word_ends(&iter2, 2);
  return gtk_text_iter_get_text(&iter1, &iter2);
  // Free memory
  g_object_unref(textbuffer);
  // Give us the result.
  return returnvalue;
}
Exemplo n.º 28
0
/* this function will add a bookmark to the current document at current cursor / selection */
static void bmark_add_current_doc_backend(Tbfwin *bfwin, const gchar *name, gint offset, gboolean is_temp) {
	GtkTextIter it, eit, sit;
	DEBUG_MSG("bmark_add_backend, adding bookmark at offset=%d for bfwin=%p\n",offset,bfwin);
	/* create bookmark */
	gtk_text_buffer_get_iter_at_offset(DOCUMENT(bfwin->current_document)->buffer,&it,offset);
	/* if there is a selection, and the offset is within the selection, we'll use it as text content */
	if (gtk_text_buffer_get_selection_bounds(DOCUMENT(bfwin->current_document)->buffer,&sit,&eit) 
				&& gtk_text_iter_in_range(&it,&sit,&eit)) {
		gchar *text = gtk_text_iter_get_text(&sit, &eit);
		bmark_add_backend(DOCUMENT(bfwin->current_document), &sit, offset, name, text, is_temp);
		g_free(text);
		
	} else {
		gchar *text;
		text = bmark_text_for_offset(DOCUMENT(bfwin->current_document), &it, offset);
		bmark_add_backend(DOCUMENT(bfwin->current_document), &it, offset, name, text, is_temp);
		g_free(text);
	}
	if (bfwin->bmark) {
		/* only if there is a left panel we should do this */
		gtk_tree_view_expand_all(bfwin->bmark);
		gtk_widget_grab_focus(bfwin->current_document->view);
	}
}
Exemplo n.º 29
0
/**
  Sprawdzenie słowa, na którym aktualnie znajduje się kursor. Ewentualne dodanie do słownika.
  @param[in] item element menu.
  @param[in] data wskaźnik na wartość.
  */
static void WhatCheck (GtkMenuItem *item, gpointer data) {
  GtkWidget *dialog;
  GtkTextIter start, end;
  char *word;
  gunichar *wword;

  //load_dictionary_from_menu(&dict);
  
  // Znajdujemy pozycję kursora
  gtk_text_buffer_get_iter_at_mark(editor_buf, &start,
                                   gtk_text_buffer_get_insert(editor_buf));

  // Jeśli nie wewnątrz słowa, kończymy
  if (!gtk_text_iter_inside_word(&start)) {
    dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_ERROR,
                                    GTK_BUTTONS_OK,
                                    "Kursor musi być w środku słowa");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    return;
  }

  // Znajdujemy początek i koniec słowa, a potem samo słowo 
  end = start;
  gtk_text_iter_backward_word_start(&start);
  gtk_text_iter_forward_word_end(&end); 
  word = gtk_text_iter_get_text(&start, &end);

  // Zamieniamy na wide char (no prawie)
  wword = g_utf8_to_ucs4_fast(word, -1, NULL);
  
  if (!make_lowercase(wword)) {
    dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                    "Podane słowo nie jest słowem słownikowym.");
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
  }
  else {
    // Sprawdzamy
    if (dictionary_find(dict, (wchar_t *)wword)) {
      dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
                                      "Wszystko w porządku,\nśpij spokojnie");
      gtk_dialog_run(GTK_DIALOG(dialog));
      gtk_widget_destroy(dialog);
    }
    else {
      // Czas korekty
      GtkWidget *vbox, *label, *combo;
      struct word_list hints;
      int i;
      wchar_t **words;

      dictionary_hints(dict, (wchar_t *)wword, &hints);
      words = (wchar_t **) word_list_get(&hints);
      dialog = gtk_dialog_new_with_buttons("Korekta", NULL, 0, 
                                           GTK_STOCK_OK,
                                           GTK_RESPONSE_ACCEPT,
                                           GTK_STOCK_ADD,
                                           GTK_RESPONSE_APPLY,
                                           GTK_STOCK_CANCEL,
                                           GTK_RESPONSE_REJECT,
                                           NULL);
      // W treści dialogu dwa elementy
      vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
      // Tekst
      label = gtk_label_new("Słowo nie znajduje się w słowniku. Wybierz \njedną z propozycji lub dodaj słowa do słownika.");
      gtk_widget_show(label);
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 1);

      // Spuszczane menu
      combo = gtk_combo_box_text_new();
      for (i = 0; i < word_list_size(&hints); i++) {
        // Combo box lubi mieć Gtk
        char *uword = g_ucs4_to_utf8((gunichar *)words[i], -1, NULL, NULL, NULL);

        // Dodajemy kolejny element
        gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), uword);
        g_free(uword);
      }
      gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
      gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 1);
      gtk_widget_show(combo);

      gint click = gtk_dialog_run(GTK_DIALOG(dialog));

      if (click == GTK_RESPONSE_ACCEPT) {
        char *korekta =
          gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo));

        // Usuwamy stare
        gtk_text_buffer_delete(editor_buf, &start, &end);
        // Wstawiamy nowe
        gtk_text_buffer_insert(editor_buf, &start, korekta, -1);
        g_free(korekta);
      }
      // Proponujemy dodanie słowa do słownika
      else if (click == GTK_RESPONSE_APPLY)
        dictionary_insert(dict, wword);
      gtk_widget_destroy(dialog);
    }
  }
  g_free(word);
  g_free(wword);
}
Exemplo n.º 30
0
Arquivo: about.c Projeto: Mortal/claws
static void about_textview_uri_update(GtkWidget *textview, gint x, gint y)
{
	GtkTextBuffer *buffer;
	GtkTextIter start_iter, end_iter;
	gchar *uri = NULL;
	gboolean same;
	
	buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));

	if (x != -1 && y != -1) {
		gint bx, by;
		GtkTextIter iter;
		GSList *tags;
		GSList *cur;
	    
		gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(textview), 
				GTK_TEXT_WINDOW_WIDGET,
				x, y, &bx, &by);
		gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(textview),
				&iter, bx, by);

		tags = gtk_text_iter_get_tags(&iter);
		for (cur = tags; cur != NULL; cur = cur->next) {
			GtkTextTag *tag = cur->data;
			char *name;

			g_object_get(G_OBJECT(tag), "name", &name, NULL);
			if (strcmp(name, "link") == 0
			    && get_tag_range(&iter, tag, &start_iter, &end_iter)) {
				uri = gtk_text_iter_get_text(&start_iter, &end_iter);
			}
			g_free(name);

			if (uri) {
				break;
			}
		}
		g_slist_free(tags);
	}

	/* compare previous hovered link and this one
	   (here links must be unique in text buffer otherwise ClickableText structures should be
	   used as in textview.c) */
	same = (uri != NULL && uri_hover != NULL
		&& strcmp((char*)uri, (char*)uri_hover) == 0);

	if (same == FALSE) {
		GdkWindow *window;

		if (uri_hover) {
			gtk_text_buffer_remove_tag_by_name(buffer,
					"link-hover",
					&uri_hover_start_iter,
					&uri_hover_end_iter);
		}
		    
		uri_hover = uri;
		if (uri) {
			uri_hover_start_iter = start_iter;
			uri_hover_end_iter = end_iter;

			gtk_text_buffer_apply_tag_by_name(buffer,
					"link-hover",
					&start_iter,
					&end_iter);
		}
		
		window = gtk_text_view_get_window(GTK_TEXT_VIEW(textview),
						GTK_TEXT_WINDOW_TEXT);
		if (!hand_cursor)
			hand_cursor = gdk_cursor_new(GDK_HAND2);
		if (!text_cursor)
			text_cursor = gdk_cursor_new(GDK_XTERM);
		gdk_window_set_cursor(window, uri ? hand_cursor : text_cursor);
	}
}