Example #1
0
void view_command_line(const gchar *text, const gchar *title, const gchar *seek,
	gboolean seek_after)
{
	GtkTextIter start, end;

	gtk_window_set_title(GTK_WINDOW(command_dialog), title ? title : _("GDB Command"));
	gtk_widget_grab_focus(command_view);

	if (text)
	{
		const gchar *pos = seek ? strstr(text, seek) : NULL;
		GtkTextIter iter;

		gtk_text_buffer_set_text(command_text, text, -1);
		gtk_text_buffer_get_iter_at_offset(command_text, &iter,
			g_utf8_strlen(text, pos ? pos + strlen(seek) * seek_after - text : -1));
		gtk_text_buffer_place_cursor(command_text, &iter);
	}

	on_command_text_changed(command_text, NULL);
	command_line_update_state(debug_state());
	gtk_text_buffer_get_start_iter(command_text, &start);
	gtk_text_buffer_get_end_iter(command_text, &end);
	gtk_text_buffer_select_range(command_text, &start, &end);
	gtk_combo_box_set_active_iter(command_history, NULL);
	gtk_dialog_run(GTK_DIALOG(command_dialog));
}
Example #2
0
static void
search_text_changed (GtkEntry *entry)
{
  ExampleAppWindow *win;
  ExampleAppWindowPrivate *priv;
  const gchar *text;
  GtkWidget *tab;
  GtkWidget *view;
  GtkTextBuffer *buffer;
  GtkTextIter start, match_start, match_end;

  text = gtk_entry_get_text (entry);

  if (text[0] == '\0')
    return;

  win = EXAMPLE_APP_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (entry)));
  priv = example_app_window_get_instance_private (win);

  tab = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
  view = gtk_bin_get_child (GTK_BIN (tab));
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));

  /* Very simple-minded search implementation */
  gtk_text_buffer_get_start_iter (buffer, &start);
  if (gtk_text_iter_forward_search (&start, text, GTK_TEXT_SEARCH_CASE_INSENSITIVE,
                                    &match_start, &match_end, NULL))
    {
      gtk_text_buffer_select_range (buffer, &match_start, &match_end);
      gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view), &match_start,
                                    0.0, FALSE, 0.0, 0.0);
    }
}
Example #3
0
void Gobby::EditCommands::on_redo()
{
	g_assert(m_current_view != NULL);

	gulong i_ = g_signal_connect_after(m_current_view->get_text_buffer(), "insert-text", G_CALLBACK(recaret_i), NULL);
	gulong e_ = g_signal_connect_after(m_current_view->get_text_buffer(), "delete-range", G_CALLBACK(recaret_e), NULL);

	inf_adopted_session_redo(
		INF_ADOPTED_SESSION(m_current_view->get_session()),
		INF_ADOPTED_USER(m_current_view->get_active_user()),
		m_current_view->get_undo_grouping().get_redo_size()
	);

	g_signal_handler_disconnect(m_current_view->get_text_buffer(), i_);
	g_signal_handler_disconnect(m_current_view->get_text_buffer(), e_);

	if(check)
	{
		GtkTextIter check_iter;
		gtk_text_buffer_get_iter_at_mark(GTK_TEXT_BUFFER(m_current_view->get_text_buffer()), &check_iter, check);
		gtk_text_buffer_select_range(GTK_TEXT_BUFFER(m_current_view->get_text_buffer()), &check_iter, &check_iter);
		gtk_text_buffer_delete_mark(GTK_TEXT_BUFFER(m_current_view->get_text_buffer()), check);
		check = NULL;
	}

	m_current_view->scroll_to_cursor_position(0.0);
}
static void
ide_editor_view_goto_line_activate (IdeEditorView    *self,
                                    const gchar      *text,
                                    EggSimplePopover *popover)
{
  gint64 value;

  g_assert (IDE_IS_EDITOR_VIEW (self));
  g_assert (EGG_IS_SIMPLE_POPOVER (popover));

  if (!ide_str_empty0 (text))
    {
      value = g_ascii_strtoll (text, NULL, 10);

      if ((value > 0) && (value < G_MAXINT))
        {
          GtkTextIter iter;
          GtkTextBuffer *buffer = GTK_TEXT_BUFFER (self->document);

          gtk_widget_grab_focus (GTK_WIDGET (self->frame1->source_view));
          gtk_text_buffer_get_iter_at_line (buffer, &iter, value - 1);
          gtk_text_buffer_select_range (buffer, &iter, &iter);
          ide_source_view_scroll_to_iter (self->frame1->source_view,
                                          &iter, 0.25, TRUE, 1.0, 0.5, TRUE);
        }
    }
}
Example #5
0
void
cmdfind_clicked (GtkWidget *widget)
{
    GtkTextIter start_iter, end_iter;
    GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
    const gchar *text = gtk_entry_get_text (GTK_ENTRY (entry_text));
    GtkTextSearchFlags flags = GTK_TEXT_SEARCH_TEXT_ONLY;
    
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (chkCase)))
        flags = flags | GTK_TEXT_SEARCH_CASE_INSENSITIVE;

    gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, 0);
    
    if (gtk_text_iter_forward_search (&start_iter, text, flags, 
                                       &start_iter, &end_iter, NULL))
    {
        gtk_text_buffer_select_range (buffer, &start_iter, &end_iter);
        gtk_text_view_scroll_to_iter (text_view,  &start_iter,
                                     0.1, FALSE, 0.5, 0.5);
    }
    else
    {
        //Status Bar show cannot find text
    }
    search_text = g_strdup (text);
}
Example #6
0
static void
insert_function_into_syntax_area (GtkTreeIter iter,
				  GtkWidget *text_view,
				  GtkTreeModel *model,
				  gpointer data
				  )
{
  GString *string;
  GValue name_value = {0};
  GValue arity_value = {0};
  gint arity;
  gint i;

  GtkTextBuffer *buffer ;

  g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));

  gtk_tree_model_get_value (model, &iter, COMPUTE_COL_NAME, &name_value);
  gtk_tree_model_get_value (model, &iter, COMPUTE_COL_ARITY, &arity_value);

  arity = g_value_get_int (&arity_value);

  string = g_string_new (g_value_get_string (&name_value));

  g_string_append (string, "(");
  for ( i = 0 ; i < arity -1 ; ++i )
    {
      g_string_append (string, "?,");
    }
  g_string_append (string, "?)");


  erase_selection (buffer);

  gtk_text_buffer_insert_at_cursor (buffer, string->str, string->len);

  g_value_unset (&name_value);
  g_value_unset (&arity_value);
  g_string_free (string, TRUE);

  /* Now position the cursor over the first '?' */
  {
    GtkTextIter insert;
    GtkTextIter selectbound;
    GtkTextMark *cursor = gtk_text_buffer_get_insert (buffer);
    gtk_text_buffer_get_iter_at_mark (buffer, &insert, cursor);
    for ( i = 0 ; i < arity ; ++i )
      {
	gtk_text_iter_backward_cursor_position (&insert);
	gtk_text_iter_backward_cursor_position (&insert);
      }
    selectbound = insert;
    gtk_text_iter_forward_cursor_position (&selectbound);

    gtk_text_buffer_select_range (buffer, &insert, &selectbound);
  }

}
Example #7
0
static gboolean ygtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
{	// on right-click, select word under cursor if there is no selection
	if (event->button == 3) {
		GtkTextView *view = GTK_TEXT_VIEW (widget);
		GtkTextBuffer *buffer = gtk_text_view_get_buffer (view);
		if (!gtk_text_buffer_get_has_selection (buffer)) {
			gint buffer_x, buffer_y;
			gtk_text_view_window_to_buffer_coords (view,
				GTK_TEXT_WINDOW_WIDGET, (gint) event->x, (gint) event->y, &buffer_x, &buffer_y);
			GtkTextIter iter;
			gtk_text_view_get_iter_at_location (view, &iter, buffer_x, buffer_y);

			if (!is_space (gtk_text_iter_get_char (&iter))) {
				GtkTextIter start, end = iter, temp = iter;
				do {
					start = temp;
					if (!gtk_text_iter_backward_char (&temp))
						break;
				} while (!is_space (gtk_text_iter_get_char (&temp)));
				do {
					if (!gtk_text_iter_forward_char (&end))
						break;
				} while (!is_space (gtk_text_iter_get_char (&end)));

				gtk_text_buffer_select_range (buffer, &start, &end);
			}
		}
	}
	return GTK_WIDGET_CLASS (ygtk_text_view_parent_class)->button_press_event (widget, event);
}
Example #8
0
/* Format->Comment Out Selection */
void
action_comment_out_selection(GtkAction *action, I7Document *document)
{
	GtkTextBuffer *buffer = GTK_TEXT_BUFFER(i7_document_get_buffer(document));
	GtkTextIter start, end;

	if(!gtk_text_buffer_get_selection_bounds(buffer, &start, &end))
		return;
	gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);

	/* Treat it as one single undo action */
	gtk_text_buffer_begin_user_action(buffer);
	/* Delete the entire text and reinsert it inside brackets, in order to
	 avoid excessively recalculating the syntax highlighting */
	gtk_text_buffer_delete(buffer, &start, &end);
	gchar *newtext = g_strconcat("[", text, "]", NULL);
	GtkTextMark *tempmark = gtk_text_buffer_create_mark(buffer, NULL, &end, TRUE);
	gtk_text_buffer_insert(buffer, &end, newtext, -1);
	gtk_text_buffer_end_user_action(buffer);

	g_free(text);
	g_free(newtext);

	/* Select the text again, including [] */
	gtk_text_buffer_get_iter_at_mark(buffer, &start, tempmark);
	gtk_text_buffer_select_range(buffer, &start, &end);
	gtk_text_buffer_delete_mark(buffer, tempmark);
}
Example #9
0
G_MODULE_EXPORT
void on_menu_selectall_activate(GtkWidget *widget, void *user)
{
  GtkTextIter start, end;
  gtk_text_buffer_get_bounds(g_e_buffer, &start, &end);
  gtk_text_buffer_select_range(g_e_buffer, &start, &end);
}
Example #10
0
static void
gimp_text_tool_select_all (GimpTextTool *text_tool,
                           gboolean      select)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);

  gimp_draw_tool_pause (GIMP_DRAW_TOOL (text_tool));

  if (select)
    {
      GtkTextIter start, end;

      gtk_text_buffer_get_bounds (buffer, &start, &end);
      gtk_text_buffer_select_range (buffer, &start, &end);
    }
  else
    {
      GtkTextIter cursor;

      gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
					gtk_text_buffer_get_insert (buffer));
      gtk_text_buffer_move_mark_by_name (buffer, "selection_bound", &cursor);
    }

  gimp_draw_tool_resume (GIMP_DRAW_TOOL (text_tool));
}
Example #11
0
void show_selection_ascii(struct selectRange *srange)
{
	g_usleep(1);
	GDK_THREADS_ENTER();
	int start, end;
	start = srange->start;
	end = srange->end;

	GtkTextView *textview3 =
	    (GtkTextView *) gtk_builder_get_object(builder, "textview3");

	GtkTextBuffer *buffer3 =
	    gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview3));
	int line1, line2;
	line1 = start / 16;
	start = start - 16 * line1;

	line2 = end / 16;
	end = end - 16 * line2;

	GtkTextIter iter1, iter2;

	gtk_text_buffer_get_iter_at_line_offset(buffer3, &iter1, line1, start);
	gtk_text_buffer_get_iter_at_line_offset(buffer3, &iter2, line2, end);
	gtk_text_buffer_select_range(buffer3, &iter1, &iter2);

	GDK_THREADS_LEAVE();
}
void
cainteoir_document_view_select_text(CainteoirDocumentView *view,
                                    gint start_pos,
                                    gint end_pos,
                                    GtkAlign anchor)
{
	GtkTextView *text_view = GTK_TEXT_VIEW(CAINTEOIR_DOCUMENT_VIEW_PRIVATE(view)->text_view);
	GtkTextBuffer *buffer = gtk_text_view_get_buffer(text_view);

	GtkTextIter start;
	gtk_text_buffer_get_iter_at_offset(buffer, &start, start_pos);

	GtkTextIter end;
	gtk_text_buffer_get_iter_at_offset(buffer, &end, end_pos);

	gtk_text_buffer_select_range(buffer, &start, &end);

	switch (anchor)
	{
	case GTK_ALIGN_START:
		gtk_text_view_scroll_to_iter(text_view, &start, 0.0, TRUE, 0.0, 0.0);
		break;
	case GTK_ALIGN_CENTER:
		gtk_text_view_scroll_to_iter(text_view, &start, 0.0, TRUE, 0.0, 0.5);
		break;
	case GTK_ALIGN_END:
		gtk_text_view_scroll_to_iter(text_view, &end, 0.0, TRUE, 0.0, 1.0);
		break;
	default:
		break;
	}
}
Example #13
0
static void treeViewSelChanged(GtkTreeView* treeView, gpointer userData)
{
	GtkTreePath* path = NULL;
	GtkTreeViewColumn* col = NULL;

	gtk_tree_view_get_cursor(treeView, &path, &col);

	GtkTreeIter iter;
	gtk_tree_model_get_iter(GTK_TREE_MODEL(treeModel), &iter, path);

	vmime::component* comp = NULL;
	gtk_tree_model_get(GTK_TREE_MODEL(treeModel), &iter, 1, &comp, -1);

	GtkTextBuffer* textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textArea));
	GtkTextIter start, end;

	gtk_text_buffer_get_iter_at_offset(textBuffer, &start, comp->getParsedOffset());
	gtk_text_buffer_get_iter_at_offset(textBuffer, &end, comp->getParsedOffset() + comp->getParsedLength());

	gtk_text_buffer_select_range(textBuffer, &start, &end);

	gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textArea), &start, 0.0, FALSE, 0.0, 0.0);

	gtk_tree_path_free(path);
}
Example #14
0
gboolean
gb_source_view_snippet_move_previous (GbSourceViewSnippet *snippet)
{
   GbSourceViewSnippetPrivate *priv;
   GbSourceViewSnippetChunk *chunk;
   GtkTextBuffer *buffer;
   GtkTextIter iter;

   g_return_val_if_fail(GB_IS_SOURCE_VIEW_SNIPPET(snippet), FALSE);

   priv = snippet->priv;

   if (--priv->tab_stop < 0) {
      buffer = gtk_text_mark_get_buffer(priv->mark_begin);
      gtk_text_buffer_get_iter_at_mark(buffer, &iter, priv->mark_begin);
      gtk_text_buffer_select_range(buffer, &iter, &iter);
      return FALSE;
   }

   if (!(chunk = gb_source_view_snippet_get_chunk_at_tab_stop(snippet, priv->tab_stop))) {
      return FALSE;
   }

   gb_source_view_snippet_chunk_select(chunk);

   return TRUE;
}
Example #15
0
static void
gb_editor_view__buffer_changed_on_volume (GbEditorView *self,
                                          GParamSpec   *pspec,
                                          IdeBuffer    *buffer)
{
  g_assert (GB_IS_EDITOR_VIEW (self));
  g_assert (IDE_IS_BUFFER (buffer));

  if (ide_buffer_get_changed_on_volume (buffer))
    gtk_revealer_set_reveal_child (self->modified_revealer, TRUE);
  else if (gtk_revealer_get_reveal_child (self->modified_revealer))
    {
      GtkTextIter iter;

      gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &iter);
      gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &iter, &iter);

      /*
       * FIXME:
       *
       * Without this delay, I see a condition with split view where the
       * non-focused split will just render blank. Well that isn't totally
       * correct, it renders empty gutters and proper line grid background. But
       * no textual content. And the adjustment is way out of sync. Even
       * changing the adjustment manually doesn't help. So whatever, I'll
       * insert a short delay and we'll pick up after the textview has
       * stablized.
       */
      g_timeout_add (10, no_really_scroll_to_the_top, g_object_ref (self));

      gtk_revealer_set_reveal_child (self->modified_revealer, FALSE);
    }
}
Example #16
0
void
gimp_text_tool_editor_button_press (GimpTextTool        *text_tool,
                                    gdouble              x,
                                    gdouble              y,
                                    GimpButtonPressType  press_type)
{
  GtkTextBuffer *buffer = GTK_TEXT_BUFFER (text_tool->buffer);
  GtkTextIter    cursor;
  GtkTextIter    selection;

  gimp_text_tool_xy_to_iter (text_tool, x, y, &cursor);

  selection = cursor;

  text_tool->select_start_iter = cursor;
  text_tool->select_words      = FALSE;
  text_tool->select_lines      = FALSE;

  switch (press_type)
    {
    case GIMP_BUTTON_PRESS_NORMAL:
      gtk_text_buffer_place_cursor (buffer, &cursor);
      break;

    case GIMP_BUTTON_PRESS_DOUBLE:
      text_tool->select_words = TRUE;

      if (! gtk_text_iter_starts_word (&cursor))
        gtk_text_iter_backward_visible_word_starts (&cursor, 1);

      if (! gtk_text_iter_ends_word (&selection) &&
          ! gtk_text_iter_forward_visible_word_ends (&selection, 1))
        gtk_text_iter_forward_to_line_end (&selection);

      gtk_text_buffer_select_range (buffer, &cursor, &selection);
      break;

    case GIMP_BUTTON_PRESS_TRIPLE:
      text_tool->select_lines = TRUE;

      gtk_text_iter_set_line_offset (&cursor, 0);
      gtk_text_iter_forward_to_line_end (&selection);

      gtk_text_buffer_select_range (buffer, &cursor, &selection);
      break;
    }
}
Example #17
0
//文章全てを選択する
void select_all(void)
{
    GtkTextIter start, end;
    
    gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(buffer), &start);
    gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(buffer), &end);
    gtk_text_buffer_select_range(GTK_TEXT_BUFFER(buffer), &start, &end);
}
Example #18
0
/* ghtml_unselect_all */
void ghtml_unselect_all(GtkWidget * widget)
{
	GHtml * ghtml;
	GtkTextIter start;

	ghtml = g_object_get_data(G_OBJECT(widget), "ghtml");
	gtk_text_buffer_get_start_iter(ghtml->tbuffer, &start);
	gtk_text_buffer_select_range(ghtml->tbuffer, &start, &start);
}
Example #19
0
void gTextArea::selDelete()
{
	GtkTextIter start, end;
	
	if (gtk_text_buffer_get_selection_bounds(_buffer, &start, &end))
	{
		gtk_text_iter_set_offset(&end, gtk_text_iter_get_offset(&start));
		gtk_text_buffer_select_range(_buffer, &start, &end);
	}
}
static void
ide_source_view_movements_select_range (Movement *mv)
{
  GtkTextBuffer *buffer;
  GtkTextMark *mark;

  g_assert (mv);
  g_assert (IDE_IS_SOURCE_VIEW (mv->self));

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (mv->self));

  if (mv->extend_selection)
    gtk_text_buffer_select_range (buffer, &mv->insert, &mv->selection);
  else
    gtk_text_buffer_select_range (buffer, &mv->insert, &mv->insert);

  mark = gtk_text_buffer_get_insert (buffer);
  gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (mv->self), mark);
}
Example #21
0
/* preview_on_select_all */
static void _preview_on_select_all(gpointer data)
{
	Preview * preview = data;
	GtkTextIter start;
	GtkTextIter end;

	gtk_text_buffer_get_start_iter(preview->view_text_tbuf, &start);
	gtk_text_buffer_get_end_iter(preview->view_text_tbuf, &end);
	gtk_text_buffer_select_range(preview->view_text_tbuf, &start, &end);
}
static void
extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
                          GtkTextIter                  *line_start)
{
	GtkTextIter start;
	GtkTextIter end;
	GtkTextIter line_end;
	GtkTextBuffer *buffer;

	buffer = get_buffer (renderer);

	gtk_text_buffer_get_selection_bounds (buffer,
	                                      &start,
	                                      &end);

	line_end = *line_start;

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

	if (gtk_text_iter_compare (&start, line_start) < 0)
	{
		gtk_text_buffer_select_range (buffer,
		                              &start,
		                              &line_end);
	}
	else if (gtk_text_iter_compare (&end, &line_end) < 0)
	{
		/* if the selection is in this line, extend
		 * the selection to the whole line */
		gtk_text_buffer_select_range (buffer,
		                              &line_end,
		                              line_start);
	}
	else
	{
		gtk_text_buffer_select_range (buffer,
		                              &end,
		                              line_start);
	}
}
Example #23
0
static gboolean
gb_vim_jump_to_line (GtkWidget      *active_widget,
                     const gchar    *command,
                     const gchar    *options,
                     GError        **error)
{
  g_assert (GTK_IS_WIDGET (active_widget));

  if (IDE_IS_EDITOR_VIEW (active_widget))
    {
      GtkSourceView  *source_view = GTK_SOURCE_VIEW (IDE_EDITOR_VIEW (active_widget)->frame1->source_view);
      GtkTextBuffer *buffer;
      gboolean extend_selection;
      gint line;

      if (!int32_parse (&line, options, 0, G_MAXINT32, "line number", error))
        return FALSE;

      buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (source_view));
      extend_selection = gtk_text_buffer_get_has_selection (buffer);
      ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), line);

      if (line == 0)
        {
          GtkTextIter iter;

          /*
           * Zero is not a valid line number, and IdeSourceView treats
           * that as a move to the end of the buffer. Instead, we want
           * line 1 to be like vi/vim.
           */
          gtk_text_buffer_get_start_iter (buffer, &iter);
          gtk_text_buffer_select_range (buffer, &iter, &iter);
          gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (source_view),
                                        gtk_text_buffer_get_insert (buffer),
                                        0.0, FALSE, 0.0, 0.0);
        }
      else
        {
          g_signal_emit_by_name (source_view,
                                 "movement",
                                 IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE,
                                 extend_selection, TRUE, TRUE);
        }

      ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), 0);

      g_signal_emit_by_name (source_view, "save-insert-mark");

      return TRUE;
    }
  else
    return gb_vim_set_source_view_error (error);
}
Example #24
0
/*
 * 'Select All'
 */
void av_editor_selectall(const av_editor *editor)
{
  GtkTextIter start, end;

  g_return_if_fail(editor != NULL
                   && editor->textview != NULL
                   && editor->textbuf != NULL);

  gtk_text_buffer_get_bounds(editor->textbuf, &start, &end);
  gtk_text_buffer_select_range(editor->textbuf, &start, &end);
}
Example #25
0
void
error_console_select_all_cmd_callback (GtkAction *action,
                                       gpointer   data)
{
  GimpErrorConsole *console = GIMP_ERROR_CONSOLE (data);
  GtkTextIter       start_iter;
  GtkTextIter       end_iter;

  gtk_text_buffer_get_bounds (console->text_buffer, &start_iter, &end_iter);
  gtk_text_buffer_select_range (console->text_buffer, &start_iter, &end_iter);
}
Example #26
0
File: text.c Project: polarcat/yad
/* searching */
static void 
do_search (GtkWidget *e, GtkWidget *w)
{
  static gchar *text = NULL;
  static guint offset;
  static GRegex *regex = NULL;
  GMatchInfo *match = NULL;
  GtkTextIter begin, end;

  g_free (pattern);
  pattern = g_strdup (gtk_entry_get_text (GTK_ENTRY (e)));
  gtk_widget_destroy (w);
  gtk_widget_queue_draw (text_view);

  if (new_search || gtk_text_buffer_get_modified (text_buffer))
    {
      /* get the text */
      g_free (text);
      gtk_text_buffer_get_bounds (text_buffer, &begin, &end);
      text = gtk_text_buffer_get_text (text_buffer, &begin, &end, FALSE);
      offset = 0;
      /* compile new regex */
      if (regex)
	g_regex_unref (regex);
      regex = g_regex_new (pattern, G_REGEX_EXTENDED | G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL);
      new_search = FALSE;
    }

  /* search and select if found */
  if (g_regex_match (regex, text + offset, G_REGEX_MATCH_NOTEMPTY, &match))
    {
      gint sp, ep, spos, epos;

      g_match_info_fetch_pos (match, 0, &sp, &ep);

      /* positions are in bytes, not character, so here we must normalize it*/
      spos = g_utf8_pointer_to_offset (text, text + sp + offset);
      epos = g_utf8_pointer_to_offset (text, text + ep + offset);

      gtk_text_buffer_get_iter_at_offset (text_buffer, &begin, spos);
      gtk_text_buffer_get_iter_at_offset (text_buffer, &end, epos);

      gtk_text_buffer_select_range (text_buffer, &begin, &end);
      gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (text_view), &begin, 0, FALSE, 0, 0);

      offset += epos;
      
      g_match_info_free (match);
      match = NULL;
    }
  else
    new_search = TRUE;
}
Example #27
0
/* compose_select_all */
void compose_select_all(Compose * compose)
{
	GtkTextBuffer * tbuf;
	GtkTextIter start;
	GtkTextIter end;

	/* FIXME another field may be in focus at the time */
	tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->view));
	gtk_text_buffer_get_start_iter(tbuf, &start);
	gtk_text_buffer_get_end_iter(tbuf, &end);
	gtk_text_buffer_select_range(tbuf, &start, &end);
}
Example #28
0
void
text_tool_clear_cmd_callback (GtkAction *action,
                              gpointer   data)
{
  GimpTextTool  *text_tool = GIMP_TEXT_TOOL (data);
  GtkTextBuffer *buffer    = GTK_TEXT_BUFFER (text_tool->buffer);
  GtkTextIter    start, end;

  gtk_text_buffer_get_bounds (buffer, &start, &end);
  gtk_text_buffer_select_range (buffer, &start, &end);
  gimp_text_tool_delete_selection (text_tool);
}
Example #29
0
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;
}
Example #30
0
void messageview_select_all(MessageView *messageview)
{
	TextView *text;

	text = messageview_get_current_textview(messageview);
	if (text) {
		GtkTextView *textview = GTK_TEXT_VIEW(text->text);
		GtkTextBuffer *buffer;
		GtkTextIter start, end;

		buffer = gtk_text_view_get_buffer(textview);
		gtk_text_buffer_get_bounds(buffer, &start, &end);
		gtk_text_buffer_select_range(buffer, &start, &end);
	}
}