コード例 #1
0
static void
ide_source_view_movements_line_chars (Movement *mv)
{
  GtkTextIter orig = mv->insert;

  /*
   * Selects the current position up to the first nonspace character.
   * If the cursor is at the line start, we will select the newline.
   * If only whitespace exists, we will select line offset of 0.
   */

  if (gtk_text_iter_starts_line (&mv->insert))
    {
      gtk_text_iter_backward_char (&mv->insert);
    }
  else
    {
      gunichar ch;

      gtk_text_iter_set_line_offset (&mv->insert, 0);

      while (!gtk_text_iter_ends_line (&mv->insert) &&
             (ch = gtk_text_iter_get_char (&mv->insert)) &&
             g_unichar_isspace (ch))
        gtk_text_iter_forward_char (&mv->insert);

      if (gtk_text_iter_ends_line (&mv->insert) ||
          (gtk_text_iter_compare (&orig, &mv->insert) <= 0))
        gtk_text_iter_set_line_offset (&mv->insert, 0);
    }

  if (!mv->exclusive)
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #2
0
/* If the last char is a newline, remove it from the buffer (otherwise
   GtkTextView shows it as an empty line). See bug #324942. */
static void
remove_ending_newline (GeditDocumentOutputStream *stream)
{
	GtkTextIter end;
	GtkTextIter start;

	gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->doc), &end);
	start = end;

	gtk_text_iter_set_line_offset (&start, 0);

	if (gtk_text_iter_ends_line (&start) &&
	    gtk_text_iter_backward_line (&start))
	{
		if (!gtk_text_iter_ends_line (&start))
		{
			gtk_text_iter_forward_to_line_end (&start);
		}

		/* Delete the empty line which is from 'start' to 'end' */
		gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->doc),
		                        &start,
		                        &end);
	}
}
コード例 #3
0
static void
ide_source_view_movements_next_char (Movement *mv)
{
  mv->count = MAX (1, mv->count);

  for (; mv->count; mv->count--)
    {
      if (gtk_text_iter_ends_line (&mv->insert))
        break;
      gtk_text_iter_forward_char (&mv->insert);
    }

  if (!mv->exclusive && !gtk_text_iter_ends_line (&mv->insert))
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #4
0
ファイル: gtksourceiter.c プロジェクト: GNOME/gtksourceview
/* Get the boundary, on @iter's line, between the end of the text and trailing
 * spaces.
 */
void
_gtk_source_iter_get_trailing_spaces_start_boundary (const GtkTextIter *iter,
						     GtkTextIter       *trailing_start)
{
	g_return_if_fail (iter != NULL);
	g_return_if_fail (trailing_start != NULL);

	*trailing_start = *iter;
	if (!gtk_text_iter_ends_line (trailing_start))
	{
		gtk_text_iter_forward_to_line_end (trailing_start);
	}

	while (!gtk_text_iter_starts_line (trailing_start))
	{
		GtkTextIter prev;
		gunichar ch;

		prev = *trailing_start;
		gtk_text_iter_backward_char (&prev);

		ch = gtk_text_iter_get_char (&prev);
		if (!g_unichar_isspace (ch))
		{
			break;
		}

		*trailing_start = prev;
	}
}
コード例 #5
0
ファイル: gimptexttool-editor.c プロジェクト: DevMaggio/gimp
static void
gimp_text_tool_enter_text (GimpTextTool *text_tool,
                           const gchar  *str)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
  gboolean       had_selection;

  had_selection = gtk_text_buffer_get_has_selection (buffer);

  gtk_text_buffer_begin_user_action (buffer);

  gimp_text_tool_delete_selection (text_tool);

  if (! had_selection && text_tool->overwrite_mode && strcmp (str, "\n"))
    {
      GtkTextIter cursor;

      gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
                                        gtk_text_buffer_get_insert (buffer));

      if (! gtk_text_iter_ends_line (&cursor))
        gimp_text_tool_delete_from_cursor (text_tool, GTK_DELETE_CHARS, 1);
    }

  gimp_text_buffer_insert (text_tool->buffer, str);

  gtk_text_buffer_end_user_action (buffer);
}
コード例 #6
0
static void
ide_source_view_movements_first_nonspace_char (Movement *mv)
{
  gunichar ch;

  if (gtk_text_iter_get_line_offset (&mv->insert) != 0)
    gtk_text_iter_set_line_offset (&mv->insert, 0);

  while (!gtk_text_iter_ends_line (&mv->insert) &&
         (ch = gtk_text_iter_get_char (&mv->insert)) &&
         g_unichar_isspace (ch))
    gtk_text_iter_forward_char (&mv->insert);

  if (!mv->exclusive && !gtk_text_iter_ends_line (&mv->insert))
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #7
0
static void
text_inserted_cb (GbColorPickerDocumentMonitor *self,
                  GtkTextIter                  *cursor,
                  gchar                        *text,
                  gint                          len,
                  GtkTextBuffer                *buffer)
{
  g_autoptr(GstyleColor) color = NULL;
  GtkTextTag *tag;
  GtkTextIter begin, end;

  g_assert (GB_IS_COLOR_PICKER_DOCUMENT_MONITOR (self));
  g_assert (GTK_IS_TEXT_BUFFER (buffer));
  g_assert (cursor != NULL);

  tag = gb_color_picker_helper_get_tag_at_iter (cursor, &color, &begin, &end);

  if (tag != NULL )
    {
      gtk_text_iter_set_line_offset (&begin, 0);
      if (!gtk_text_iter_ends_line (&end))
        gtk_text_iter_forward_to_line_end (&end);

      gb_color_picker_document_monitor_queue_uncolorize (self, &begin, &end);
    }
}
コード例 #8
0
static void
ide_source_view_movements_middle_char (Movement *mv)
{
  GtkTextView *text_view = GTK_TEXT_VIEW (mv->self);
  GdkWindow *window;
  GdkRectangle rect;
  guint line_offset;
  int width;
  int chars_in_line;

  gtk_text_view_get_iter_location (text_view, &mv->insert, &rect);
  window = gtk_text_view_get_window (text_view, GTK_TEXT_WINDOW_TEXT);

  width = gdk_window_get_width (window);
  if (rect.width <= 0)
    return;

  chars_in_line = width / rect.width;
  if (chars_in_line == 0)
    return;

  gtk_text_iter_set_line_offset (&mv->insert, 0);

  for (line_offset = chars_in_line / 2; line_offset; line_offset--)
    if (!gtk_text_iter_forward_char (&mv->insert))
      break;

  if (!mv->exclusive)
    if (!gtk_text_iter_ends_line (&mv->insert))
      gtk_text_iter_forward_char (&mv->insert);
}
コード例 #9
0
static void
text_inserted_after_cb (GbColorPickerDocumentMonitor *self,
                        GtkTextIter                  *iter,
                        gchar                        *text,
                        gint                          len,
                        GtkTextBuffer                *buffer)
{
  GtkTextIter begin, end;
  gint offset;

  g_assert (GB_IS_COLOR_PICKER_DOCUMENT_MONITOR (self));
  g_assert (GTK_IS_TEXT_BUFFER (buffer));
  g_assert (iter != NULL);

  begin = *iter;
  offset = gtk_text_iter_get_offset (&begin);
  gtk_text_iter_set_offset (&begin, offset - len);
  gtk_text_iter_set_line_offset (&begin, 0);

  end = *iter;
  if (!gtk_text_iter_ends_line (&end))
    gtk_text_iter_forward_to_line_end (&end);

  gb_color_picker_document_monitor_queue_colorize (self, &begin, &end);
}
コード例 #10
0
gboolean
gtk_source_completion_words_utils_forward_word_end (GtkTextIter    *iter,
                                                    CharacterCheck  valid,
                                                    gpointer        data)
{
	/* Go backward as long as there are word characters */
	while (TRUE)
	{
		/* Ending a line is good */
		if (gtk_text_iter_ends_line (iter))
		{
			break;
		}
		
		/* Check if the next character is a valid word character */
		if (!valid (gtk_text_iter_get_char (iter), data))
		{
			break;
		}
		
		gtk_text_iter_forward_char (iter);
	}
	
	return TRUE;
}
コード例 #11
0
ファイル: menu_edit.c プロジェクト: kawatea/cedit
//カーソルのある行を削除する
void kill_line(void)
{
    int delete_flag = 0;
    GtkTextIter start, end;
    GtkClipboard *clipboard = gtk_widget_get_clipboard(view, GDK_SELECTION_CLIPBOARD);
    
    buf[0] = '\0';
    if (kill_flag == 1) {
        char *text = gtk_clipboard_wait_for_text(clipboard);
        strcat(buf, text);
        free(text);
    }
    
    gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(buffer), &start, gtk_text_buffer_get_insert(GTK_TEXT_BUFFER(buffer)));
    end = start;
    gtk_text_iter_forward_line(&end);
    if (!gtk_text_iter_starts_line(&start) && !gtk_text_iter_ends_line(&start) && !gtk_text_iter_is_end(&end) && kill_flag == 0) gtk_text_iter_backward_char(&end);
    
    char *text = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(buffer), &start, &end, TRUE);
    strcat(buf, text);
    free(text);
    
    if (buf[0] != '\0') delete_flag = 1;
    
    gtk_clipboard_set_text(clipboard, buf, -1);
    gtk_text_buffer_delete(GTK_TEXT_BUFFER(buffer), &start, &end);
    
    kill_flag = delete_flag;
}
コード例 #12
0
ファイル: actions.c プロジェクト: ptomato/gnome-inform7
/* Format->Indent */
void
action_indent(GtkAction *action, I7Document *document)
{
	GtkTextBuffer *buffer = GTK_TEXT_BUFFER(i7_document_get_buffer(document));
	/* Shift the selected lines in the buffer one tab to the right */
	/* Adapted from gtksourceview.c */
	GtkTextIter start, end;
	gtk_text_buffer_get_selection_bounds(buffer, &start, &end);
	/* Find out which lines to indent */
	gint start_line = gtk_text_iter_get_line(&start);
	gint end_line = gtk_text_iter_get_line(&end);
	gint i;

	/* if the end of the selection is before the first character on a line,
	don't indent it */
	if((gtk_text_iter_get_visible_line_offset(&end) == 0) && (end_line > start_line))
		end_line--;

	/* Treat it as one single undo action */
	gtk_text_buffer_begin_user_action(buffer);
	for(i = start_line; i <= end_line; i++) {
		GtkTextIter iter;
		gtk_text_buffer_get_iter_at_line(buffer, &iter, i);

		/* don't add indentation on empty lines */
		if(gtk_text_iter_ends_line(&iter))
			continue;

		gtk_text_buffer_insert(buffer, &iter, "\t", -1);
	}
	gtk_text_buffer_end_user_action(buffer);
}
コード例 #13
0
ファイル: scoreviewer.c プロジェクト: Moeryn/bmc
/**
 * \fn void external_link_catch(GtkWidget *w, GObject *link)
 * \brief This function catch the signal when a clic is made on a note.
 * \param w The widget which triggered the call.
 * \param link ev_link_action.
 * \param editor The GUI structure.
 */
void external_link_catch(GtkWidget *widget, GObject *link, BrailleMusicEditor *editor) {
    EvLinkAction *l = EV_LINK_ACTION(link);
    ev_view_copy_link_address(EV_VIEW(widget), l);
    //get line:column link
    const gchar * lc = ev_link_action_get_uri(l);
    int line, column;
    int i = 0;
    char c = ' ', temp[2048];
    while(c != ':' || i >= strlen(lc)) {
        c = lc[i];
        temp[i] = c;
        i++;
    }
    temp[i+1]='\0';
    line = atoi(temp);
    line--;
    column = atoi(lc+i);
    GtkTextIter it;
    GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(editor->textview));
    if(gtk_text_buffer_get_line_count(buffer) < line ) {
        line = 0;
        column = 0;
    }

    gtk_text_buffer_get_iter_at_line(buffer, &it, line);
    while(column >0 && !gtk_text_iter_ends_line(&it)) {
        gtk_text_iter_forward_char(&it);
        column--;
    }
    gtk_widget_grab_focus(editor->textview);
    gtk_text_buffer_place_cursor(buffer, &it);
    gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(editor->textview), &it, 0.0, FALSE, 0.5, 0.5);
}
コード例 #14
0
static void
ide_source_view_movements_line_end (Movement *mv)
{
  if (!gtk_text_iter_ends_line (&mv->insert))
    gtk_text_iter_forward_to_line_end (&mv->insert);

  if (!mv->exclusive)
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #15
0
static gboolean
text_iter_forward_to_nonspace_captive (GtkTextIter *iter)
{
  while (!gtk_text_iter_ends_line (iter) && g_unichar_isspace (gtk_text_iter_get_char (iter)))
    if (!gtk_text_iter_forward_char (iter))
      return FALSE;

  return !g_unichar_isspace (gtk_text_iter_get_char (iter));
}
コード例 #16
0
ファイル: smie-gtksourceview.c プロジェクト: ueno/c-smie
static gboolean
smie_gtk_source_buffer_forward_to_line_end (gpointer data)
{
  smie_gtk_source_buffer_context_t *context = data;
  /* If we are already on the EOL, do nothing.  */
  if (gtk_text_iter_ends_line (&context->iter))
    return FALSE;
  return gtk_text_iter_forward_to_line_end (&context->iter);
}
コード例 #17
0
/* Removes indent that is mean to be changes and inserts
 * tabs and/or spaces insted */
static void
gbp_retab_editor_page_addin_retab (GtkTextBuffer *buffer,
                            gint           line,
                            gint           tab_width,
                            gint           indent,
                            gboolean       to_spaces)
{
  g_autoptr(GString) new_indent = g_string_new (NULL);
  GtkTextIter iter;
  GtkTextIter begin;
  GtkTextIter end;
  gint tab_num = 0;
  gint space_num = 0;

  g_assert (GTK_IS_TEXT_BUFFER (buffer));
  g_assert (line >= 0 && line < gtk_text_buffer_get_line_count(buffer));
  g_assert (tab_width != 0);
  g_assert (new_indent != NULL);

  gtk_text_buffer_get_iter_at_line (buffer, &iter, line);

  while (!gtk_text_iter_ends_line (&iter) &&
         g_unichar_isspace(gtk_text_iter_get_char (&iter)))
    {
      if (gtk_text_iter_get_char (&iter) == ' ')
        ++space_num;
      else if (gtk_text_iter_get_char (&iter) == '\t')
        ++tab_num;

      gtk_text_iter_forward_char (&iter);
    }

  if (to_spaces)
    {
      for (gint tab = 0; tab < tab_num * tab_width; ++tab)
        g_string_append_c(new_indent, ' ');

      for (gint space = 0; space < space_num; ++space)
        g_string_append_c(new_indent, ' ');
    }
  else
    {
      for (gint tab = 0; tab < tab_num + (space_num / tab_width); ++tab)
        g_string_append_c(new_indent, '\t');

      for (gint space = 0; space < space_num % tab_width; ++space)
        g_string_append_c(new_indent, ' ');
    }

  gtk_text_buffer_get_iter_at_line(buffer, &begin, line);
  gtk_text_buffer_get_iter_at_line_offset (buffer, &end, line, indent);
  gtk_text_buffer_delete (buffer, &begin, &end);

  if (new_indent->len)
    gtk_text_buffer_insert (buffer, &begin, new_indent->str, new_indent->len);
}
コード例 #18
0
static void
ide_source_view_movements_last_char (Movement *mv)
{
  if (!gtk_text_iter_ends_line (&mv->insert))
    {
      gtk_text_iter_forward_to_line_end (&mv->insert);
      if (mv->exclusive && !gtk_text_iter_starts_line (&mv->insert))
        gtk_text_iter_backward_char (&mv->insert);
    }
}
コード例 #19
0
ファイル: comments-dialog.c プロジェクト: RobertDash/pspp
static char *
generate_syntax (const struct comment_dialog *cd)
{
    gint i;

    GString *str;
    gchar *text;
    GtkWidget *tv = get_widget_assert (cd->xml, "comments-textview1");
    GtkWidget *check = get_widget_assert (cd->xml, "comments-checkbutton1");
    GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv));

    str = g_string_new ("\n* Data File Comments.\n\n");

    if (dict_get_documents (cd->dict->dict) != NULL)
        g_string_append (str, "DROP DOCUMENTS.\n");

    g_string_append (str, "ADD DOCUMENT\n");

    for (i = 0 ; i < gtk_text_buffer_get_line_count (buffer) ; ++i )
    {
        struct string tmp;
        GtkTextIter start;
        char *line;

        gtk_text_buffer_get_iter_at_line (buffer, &start, i);
        if (gtk_text_iter_ends_line (&start))
            line = g_strdup ("");
        else
        {
            GtkTextIter end = start;
            gtk_text_iter_forward_to_line_end (&end);
            line = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
        }

        ds_init_empty (&tmp);
        syntax_gen_string (&tmp, ss_cstr (line));
        g_free (line);

        g_string_append_printf (str, " %s\n", ds_cstr (&tmp));

        ds_destroy (&tmp);
    }
    g_string_append (str, " .\n");



    if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
        g_string_append (str, "DISPLAY DOCUMENTS.\n");

    text = str->str;

    g_string_free (str, FALSE);

    return text;
}
コード例 #20
0
/* Always process start and end by init_boudaries before */
static GHashTable *
gbp_spell_navigator_count_words (GbpSpellNavigator *self,
                                 GtkTextIter       *start,
                                 GtkTextIter       *end)
{
  GHashTable *table;
  GtkSourceRegion *words_count_region;
  WordsCountState *state;
  GtkTextIter start_subregion;
  GtkTextIter end_subregion;
  gint line_start;
  gint line_end;
  gint nb_subregion;

  g_assert (GBP_IS_SPELL_NAVIGATOR (self));
  g_assert (start != NULL);
  g_assert (end != NULL);

  words_count_region = gtk_source_region_new (self->buffer);
  line_start = gtk_text_iter_get_line (start);
  line_end = gtk_text_iter_get_line (end);
  nb_subregion = (line_end - line_start + 1) / SPELLCHECKER_SUBREGION_LENGTH;

  if (nb_subregion > 1)
    {
      for (gint i = 0; i < nb_subregion; ++i)
        {
          line_end = line_start + SPELLCHECKER_SUBREGION_LENGTH - 1;
          gtk_text_buffer_get_iter_at_line_offset (self->buffer, &start_subregion, line_start, 0);
          gtk_text_buffer_get_iter_at_line_offset (self->buffer, &end_subregion, line_end, 0);
          if (!gtk_text_iter_ends_line (&end_subregion))
            gtk_text_iter_forward_to_line_end (&end_subregion);

          gtk_source_region_add_subregion (words_count_region, &start_subregion, &end_subregion);
          line_start = line_end + 1;
        }
    }

  gtk_text_buffer_get_iter_at_line_offset (self->buffer, &start_subregion, line_start, 0);
  gtk_source_region_add_subregion (words_count_region, &start_subregion, end);

  table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

  state = g_slice_new0 (WordsCountState);
  state->navigator = g_object_ref (self);
  state->words_count_region = words_count_region;
  gtk_source_region_get_start_region_iter (words_count_region, &state->iter);

  g_idle_add_full (G_PRIORITY_LOW,
                   (GSourceFunc)gbp_spell_navigator_words_count_cb,
                   state,
                   (GDestroyNotify)words_count_state_free);

  return table;
}
コード例 #21
0
ファイル: mousepad-util.c プロジェクト: ali1234/mousepad
gboolean
mousepad_util_iter_forward_text_start (GtkTextIter *iter)
{
  g_return_val_if_fail (!mousepad_util_iter_inside_word (iter), FALSE);

  /* keep until we hit text or a line end */
  while (g_unichar_isspace (gtk_text_iter_get_char (iter)))
    if (gtk_text_iter_ends_line (iter) || !gtk_text_iter_forward_char (iter))
      break;

  return TRUE;
}
コード例 #22
0
ファイル: Utils.c プロジェクト: chan18/ljedit
static gboolean search_elem_locate(GtkTextBuffer* buf, gint* pline, gint* poffset, CppElem* elem) {
	GtkTextIter iter;
	GtkTextIter limit;
	GtkTextIter ps;
	GtkTextIter pe;
	guint ch;
	gboolean full_matched;
	gboolean need_move_cursor;

	*pline = elem->sline - 1;
	*poffset = -1;

	gtk_text_buffer_get_iter_at_line(buf, &iter, *pline);
	limit = iter;
	gtk_text_iter_forward_to_line_end(&limit);

	need_move_cursor = TRUE;
	full_matched = FALSE;
	while( gtk_text_iter_forward_search(&iter, elem->name->buf, 0, &ps, &pe, &limit) ) {
		*poffset = gtk_text_iter_get_line_offset(&pe);
		gtk_text_buffer_select_range(buf, &pe, &ps);
		need_move_cursor = FALSE;

		if( gtk_text_iter_starts_line(&ps) ) {
			full_matched = TRUE;
		} else {
			iter = ps;
			gtk_text_iter_backward_char(&iter);
			ch = gtk_text_iter_get_char(&iter);
			if( !g_unichar_isalnum(ch) && ch!='_' )
				full_matched = TRUE;
		}

		if( full_matched && !gtk_text_iter_ends_line(&pe) ) {
			iter = pe;
			gtk_text_iter_forward_char(&iter);
			ch = gtk_text_iter_get_char(&iter);
			if( g_unichar_isalnum(ch) || ch=='_' )
				full_matched = FALSE;
		}

		if( full_matched )
			break;

		iter = ps;
		gtk_text_iter_forward_char(&iter);
	}

	return need_move_cursor;
}
コード例 #23
0
static void
ide_source_view_movements_previous_word_end (Movement *mv)
{
  GtkTextIter copy;

  copy = mv->insert;

  _ide_vim_iter_backward_word_end (&mv->insert);

  /*
   * Vim treats an empty line as a word.
   */
  while ((gtk_text_iter_compare (&copy, &mv->insert) > 0) &&
         gtk_text_iter_backward_char (&copy))
    {
      if (gtk_text_iter_starts_line (&copy) &&
          gtk_text_iter_ends_line (&copy))
        mv->insert = copy;
    }

  if (!mv->exclusive && !gtk_text_iter_ends_line (&mv->insert))
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #24
0
static void
ide_source_view_movements_nth_char (Movement *mv)
{
  gtk_text_iter_set_line_offset (&mv->insert, 0);

  for (; mv->count > 0; mv->count--)
    {
      if (gtk_text_iter_ends_line (&mv->insert))
        break;
      gtk_text_iter_forward_char (&mv->insert);
    }

  if (!mv->exclusive)
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #25
0
static void
ide_source_view_movements_next_full_word_start (Movement *mv)
{
  GtkTextIter copy;

  copy = mv->insert;

  _ide_vim_iter_forward_WORD_start (&mv->insert);

  /* prefer an empty line before word */
  text_iter_forward_to_empty_line (&copy, &mv->insert);
  if (gtk_text_iter_compare (&copy, &mv->insert) < 0)
    mv->insert = copy;

  if (!mv->exclusive && !gtk_text_iter_ends_line (&mv->insert))
    gtk_text_iter_forward_char (&mv->insert);
}
コード例 #26
0
ファイル: operation-save.cpp プロジェクト: Kaligule/gobby
Gobby::OperationSave::OperationSave(Operations& operations,
                                    TextSessionView& view,
                                    const Glib::RefPtr<Gio::File>& file,
                                    const std::string& encoding,
                                    DocumentInfoStorage::EolStyle eol_style):
	Operation(operations), m_file(file), m_view(&view),
	m_start_time(std::time(NULL)), m_current_line_index(0),
	m_encoding(encoding), m_eol_style(eol_style),
	m_storage_key(view.get_info_storage_key()),
	m_iconv(encoding.c_str(), "UTF-8"),
	m_buffer_size(0), m_buffer_index(0)
{
	const Folder& folder = get_folder_manager().get_text_folder();
	folder.signal_document_removed().connect(
		sigc::mem_fun(*this, &OperationSave::on_document_removed));

	// Load content so that the session can go on while saving
	GtkTextBuffer* buffer = GTK_TEXT_BUFFER(view.get_text_buffer());
	GtkTextIter prev;
	GtkTextIter pos;
	GtkTextIter old_pos;

	gtk_text_buffer_get_start_iter(buffer, &prev);
	pos = prev;

	if(!gtk_text_iter_ends_line(&pos))
		gtk_text_iter_forward_to_line_end(&pos);

	do
	{
		Line line;
		line.first =
			gtk_text_buffer_get_text(buffer, &prev, &pos, TRUE);
		line.second = gtk_text_iter_get_line_index(&pos);
		m_lines.push_back(line);

		//if(gtk_text_iter_is_end(&prev))
		//	break;

		old_pos = pos;
		gtk_text_iter_forward_line(&prev);
		gtk_text_iter_forward_to_line_end(&pos);
	} while(!gtk_text_iter_equal(&pos, &old_pos));

	m_current_line = m_lines.begin();
}
コード例 #27
0
static gboolean
text_iter_forward_to_empty_line (GtkTextIter *iter,
                                 GtkTextIter *bounds)
{
  if (!gtk_text_iter_forward_char (iter))
    return FALSE;

  while (gtk_text_iter_compare (iter, bounds) < 0)
    {
      if (gtk_text_iter_starts_line (iter) && gtk_text_iter_ends_line (iter))
        return TRUE;
      if (!gtk_text_iter_forward_char (iter))
        return FALSE;
    }

  return FALSE;
}
コード例 #28
0
ファイル: ide-indenter.c プロジェクト: GNOME/gnome-builder
static gchar *
ide_indenter_mimic_source_view (GtkTextView *text_view,
                                GtkTextIter *begin,
                                GtkTextIter *end,
                                gint        *cursor_offset,
                                GdkEventKey *event)
{
  GtkTextIter copy_begin;
  GtkTextIter copy_end;
  gchar *ret;

  IDE_ENTRY;

  g_assert (GTK_IS_TEXT_VIEW (text_view));
  g_assert (begin != NULL);
  g_assert (end != NULL);
  g_assert (cursor_offset != NULL);
  g_assert (event != NULL);

  *cursor_offset = 0;
  *begin = *end;

  if (event->keyval != GDK_KEY_Return &&
      event->keyval != GDK_KEY_KP_Enter)
    IDE_RETURN (NULL);

  copy_begin = *end;

  /* We might already be at the beginning of the file */
  if (!gtk_text_iter_backward_char (&copy_begin))
    IDE_RETURN (NULL);

  gtk_text_iter_set_line_offset (&copy_begin, 0);
  copy_end = copy_begin;
  while (g_unichar_isspace (gtk_text_iter_get_char (&copy_end)))
    {
      if (gtk_text_iter_ends_line (&copy_end) ||
          !gtk_text_iter_forward_char (&copy_end))
        break;
    }

  ret = gtk_text_iter_get_slice (&copy_begin, &copy_end);

  IDE_RETURN (ret);
}
コード例 #29
0
static gint
get_buffer_range_indent (GtkTextBuffer *buffer,
                         gint           line,
                         gboolean       to_spaces)
{
  GtkTextIter iter;
  gint indent = 0;

  gtk_text_buffer_get_iter_at_line (buffer, &iter, line);

  while (!gtk_text_iter_ends_line (&iter) && g_unichar_isspace(gtk_text_iter_get_char (&iter)))
    {
      gtk_text_iter_forward_char (&iter);
      ++indent;
    }

  return indent;
}
コード例 #30
0
static void
select_line (GtkSourceGutterRendererLines *renderer,
             GtkTextIter                  *line_start)
{
	GtkTextIter iter;
	GtkTextBuffer *buffer;

	buffer = get_buffer (renderer);

	iter = *line_start;

	if (!gtk_text_iter_ends_line (&iter))
	{
		gtk_text_iter_forward_to_line_end (&iter);
	}

	/* Select the line, put the cursor at the end of the line */
	gtk_text_buffer_select_range (buffer, &iter, line_start);
}