예제 #1
0
파일: plugin.c 프로젝트: VujinovM/anjuta
static void
on_toggle_comment (GtkAction *action, gpointer data)
{
    gint line;
    gboolean has_selection;

    CppJavaPlugin *lang_plugin;
    IAnjutaEditor *editor;
    lang_plugin = ANJUTA_PLUGIN_CPP_JAVA (data);
    editor = IANJUTA_EDITOR (lang_plugin->current_editor);

    ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT(editor), NULL);

    has_selection = ianjuta_editor_selection_has_selection
                        (IANJUTA_EDITOR_SELECTION (editor), NULL);
    if (has_selection)
    {
        IAnjutaIterable *sel_start, *sel_end;
        sel_start = ianjuta_editor_selection_get_start (IANJUTA_EDITOR_SELECTION (editor),
                                                        NULL);
        sel_end = ianjuta_editor_selection_get_end (IANJUTA_EDITOR_SELECTION (editor),
                                                    NULL);
        toggle_comment_multiline (editor, sel_start, sel_end);
        g_object_unref (sel_start);
        g_object_unref (sel_end);
    }
    else
    {
        line = ianjuta_editor_get_lineno (IANJUTA_EDITOR(editor), NULL);
        toggle_comment_singleline (lang_plugin, editor, line);
    }
    ianjuta_document_end_undo_action (IANJUTA_DOCUMENT(editor), NULL);
}
예제 #2
0
void
cpp_auto_indentation (IAnjutaEditor *editor,
                      IndentCPlugin *lang_plugin,
                      IAnjutaIterable *start,
                      IAnjutaIterable *end)
{
	gint line_start, line_end;
	gint insert_line;
	gint line_indent;
	gboolean has_selection;

	has_selection = ianjuta_editor_selection_has_selection
		(IANJUTA_EDITOR_SELECTION (editor), NULL);
	if (start == NULL || end == NULL)
	{
		if (has_selection)
		{
			IAnjutaIterable *sel_start, *sel_end;
			sel_start = ianjuta_editor_selection_get_start (IANJUTA_EDITOR_SELECTION (editor),
				                                            NULL);
			sel_end = ianjuta_editor_selection_get_end (IANJUTA_EDITOR_SELECTION (editor),
				                                        NULL);
			line_start = ianjuta_editor_get_line_from_position (editor, sel_start, NULL);
			line_end = ianjuta_editor_get_line_from_position (editor, sel_end, NULL);
			g_object_unref (sel_start);
			g_object_unref (sel_end);
		}
		else
		{
			line_start = ianjuta_editor_get_lineno (IANJUTA_EDITOR(editor), NULL);
			line_end = line_start;
		}
	}
	else
	{
			line_start = ianjuta_editor_get_line_from_position (editor, start, NULL);
			line_end = ianjuta_editor_get_line_from_position (editor, end, NULL);
	}
	ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT(editor), NULL);

	for (insert_line = line_start; insert_line <= line_end; insert_line++)
	{
		gint parenthesis_indentation = 0;
		line_indent = get_line_auto_indentation (lang_plugin, editor,
		                                         insert_line,
		                                         &parenthesis_indentation);
		/* DEBUG_PRINT ("Line indent for line %d = %d", insert_line, line_indent); */
		set_line_indentation (lang_plugin, editor, insert_line, line_indent, parenthesis_indentation);
	}
	ianjuta_document_end_undo_action (IANJUTA_DOCUMENT(editor), NULL);
}
예제 #3
0
/* CHECKME unused */
void
anjuta_docman_reload_file (AnjutaDocman *docman, GFile* file)
{
	IAnjutaDocument *doc;

	g_return_if_fail (file != NULL);

	doc = anjuta_docman_get_document_for_file (docman, file);
	if (doc && IANJUTA_IS_EDITOR (doc))
	{
		IAnjutaEditor *te;
		te = IANJUTA_EDITOR (doc);
		glong nNowPos = ianjuta_editor_get_lineno (te, NULL);
		ianjuta_file_open (IANJUTA_FILE (doc), file, NULL);
		ianjuta_editor_goto_line (te, nNowPos, NULL);
	}
}
예제 #4
0
/**
 * parser_cxx_assist_parse_expression:
 * @assist: self,
 * @iter: current cursor position
 * @start_iter: return location for the start of the completion
 * 
 * Returns: An iter of a list of IAnjutaSymbols or NULL
 */
static IAnjutaIterable*
parser_cxx_assist_parse_expression (ParserCxxAssist* assist, IAnjutaIterable* iter, IAnjutaIterable** start_iter)
{
	IAnjutaEditor* editor = IANJUTA_EDITOR (assist->priv->iassist);
	IAnjutaIterable* res = NULL;
	IAnjutaIterable* cur_pos = ianjuta_iterable_clone (iter, NULL);
	gboolean op_start = FALSE;
	gboolean ref_start = FALSE;
	gchar* stmt = NULL;
	
	/* Cursor points after the current characters, move back */
	ianjuta_iterable_previous (cur_pos, NULL);
	
	/* Search for a operator in the current line */
	do 
	{
		gchar ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL(cur_pos),
		                                         0, NULL);
		
		if (parser_cxx_assist_is_expression_separator(ch, FALSE, iter)) {
			break;
		}

		if (ch == '.' || (op_start && ch == '-') || (ref_start && ch == ':'))
		{
			/* Found an operator, get the statement and the pre_word */
			IAnjutaIterable* pre_word_start = ianjuta_iterable_clone (cur_pos,
			                                                          NULL);
			IAnjutaIterable* pre_word_end = ianjuta_iterable_clone (iter, NULL);
			IAnjutaIterable* stmt_end = ianjuta_iterable_clone (pre_word_start,
			                                                    NULL);

			
			/* we need to pass to the parser all the statement included the last
			 * operator, being it "." or "->" or "::"
			 * Increase the end bound of the statement.
			 */
			ianjuta_iterable_next (stmt_end, NULL);
			if (op_start == TRUE || ref_start == TRUE)
				ianjuta_iterable_next (stmt_end, NULL);
				
			
			/* Move one character forward so we have the start of the pre_word
			 * and not the last operator */
			ianjuta_iterable_next (pre_word_start, NULL);
			/* If this is a two character operator, skip the second character */
			if (op_start)
			{
				ianjuta_iterable_next (pre_word_start, NULL);
			}
			
			parser_cxx_assist_update_pre_word (assist, ianjuta_editor_get_text (
			                                                   editor,
			                                                   pre_word_start,
			                                                   pre_word_end,
			                                                   NULL));

			/* Try to get the name of the variable */
			while (ianjuta_iterable_previous (cur_pos, NULL))
			{
				gchar word_ch = ianjuta_editor_cell_get_char (
				                        IANJUTA_EDITOR_CELL(cur_pos), 0, NULL);
				
				if (parser_cxx_assist_is_expression_separator(word_ch, FALSE,
				                                              cur_pos)) 
					break;				
			}
			ianjuta_iterable_next (cur_pos, NULL);
			stmt = ianjuta_editor_get_text (editor,
			                                cur_pos, stmt_end, NULL);
			*start_iter = pre_word_start;
			g_object_unref (stmt_end);
			g_object_unref (pre_word_end);
			break;
		}
		else if (ch == '>')
			op_start = TRUE;
		else if (ch == ':')
			ref_start = TRUE;
		else
		{
			op_start = FALSE;
			ref_start = FALSE;
		}
	}
	while (ianjuta_iterable_previous (cur_pos, NULL));

	if (stmt)
	{
		gint lineno;
		gchar *above_text;
		IAnjutaIterable* start;
		
		if (!assist->priv->editor_filename)
		{
			g_free (stmt);
			return NULL;
		}
		
		start = ianjuta_editor_get_start_position (editor, NULL);
		above_text = ianjuta_editor_get_text (editor, start, iter, NULL);
		g_object_unref (start);
		
		lineno = ianjuta_editor_get_lineno (editor, NULL);

		/* the parser works even for the "Gtk::" like expressions, so it 
		 * shouldn't be created a specific case to handle this.
		 */
		res = engine_parser_process_expression (stmt,
		                                        above_text,
		                                        assist->priv->editor_filename,
		                                        lineno);
		g_free (stmt);
	}
	g_object_unref (cur_pos);
	return res;
}
예제 #5
0
IAnjutaEditor *
anjuta_docman_goto_file_line_mark (AnjutaDocman *docman, GFile* file,
								   gint line, gboolean mark)
{
	IAnjutaDocument *doc;
	IAnjutaEditor *te;
	AnjutaDocmanPage *page;

	g_return_val_if_fail (file != NULL, NULL);

	if (!g_file_query_exists (file, NULL))
	{
		return NULL;
	}

	/* Save current uri and line in document history list */
	page = anjuta_docman_get_current_page (docman);
	if (page && page->doc && IANJUTA_IS_FILE (page->doc))
	{
		GFile* file = ianjuta_file_get_file (IANJUTA_FILE (page->doc), NULL);

		if (file)
		{
			gint line = 0;

			if (IANJUTA_IS_EDITOR (page->doc))
			{
				line = ianjuta_editor_get_lineno (IANJUTA_EDITOR (page->doc), NULL);
			}

			an_file_history_push (file, line);
		}
	}

	/* if possible, use a document that's already open */
	doc = anjuta_docman_get_document_for_file (docman, file);
	if (doc == NULL)
	{
		te = anjuta_docman_add_editor (docman, file, NULL);
		doc = IANJUTA_DOCUMENT (te);
	}
	else if (IANJUTA_IS_EDITOR (doc))
	{
		te = IANJUTA_EDITOR (doc);
	}
	else
	{
		doc = NULL;
		te = NULL;
	}

	if (te != NULL)
	{
		if (line >= 0)
		{
			ianjuta_editor_goto_line (te, line, NULL);
			if (mark && IANJUTA_IS_MARKABLE (doc))
			{
				ianjuta_markable_delete_all_markers (IANJUTA_MARKABLE (doc),
													IANJUTA_MARKABLE_LINEMARKER,
													NULL);
				ianjuta_markable_mark (IANJUTA_MARKABLE (doc), line,
									  IANJUTA_MARKABLE_LINEMARKER, NULL, NULL);
			}
		}
	}
	if (doc != NULL)
	{
		anjuta_docman_present_notebook_page (docman, doc);
		ianjuta_document_grab_focus (IANJUTA_DOCUMENT (doc), NULL);
	}

	return te;
}
예제 #6
0
void
cpp_java_indentation_char_added (IAnjutaEditor *editor,
                                 IAnjutaIterable *insert_pos,
                                 gchar ch,
                                 IndentCPlugin *plugin)
{
	IAnjutaEditorAttribute attrib;
	IAnjutaIterable *iter;
	gboolean should_auto_indent = FALSE;

	iter = ianjuta_iterable_clone (insert_pos, NULL);

	/* If autoindent is enabled*/
	if (plugin->smart_indentation)
	{

		/* DEBUG_PRINT ("Char added at position %d: '%c'", insert_pos, ch); */

		if (iter_is_newline (iter, ch))
		{
			skip_iter_to_newline_head (iter, ch);
			/* All newline entries means enable indenting */
			should_auto_indent = TRUE;
		}
		else if (ch == '{' || ch == '}' || ch == '#')
		{
			/* Indent only when it's the first non-white space char in the line */

			/* Don't bother if we are inside string */
			attrib = ianjuta_editor_cell_get_attribute (IANJUTA_EDITOR_CELL (iter),
			                                            NULL);
			if (attrib != IANJUTA_EDITOR_STRING)
			{
				/* Iterate backwards till the begining of the line and disable
				 * indenting if any non-white space char is encountered
				 */

				/* Begin by assuming it should be indented */
				should_auto_indent = TRUE;

				while (ianjuta_iterable_previous (iter, NULL))
				{
					ch = ianjuta_editor_cell_get_char (IANJUTA_EDITOR_CELL (iter),
					                                   0, NULL);

					//DEBUG_PRINT ("Looking at char '%c'", ch);

					/* Break on begining of line (== end of previous line) */
					if (iter_is_newline (iter, ch))
					{
						skip_iter_to_newline_head (iter, ch);
						break;
					}
					/* If a non-white space char is encountered, disabled indenting */
					if (!isspace (ch))
					{
						should_auto_indent = FALSE;
						break;
					}
				}
			}
		}
		if (should_auto_indent)
		{
			gint insert_line;
			gint line_indent;
			gint parenthesis_indentation;

			ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT(editor), NULL);

			insert_line = ianjuta_editor_get_lineno (editor, NULL);
			line_indent = get_line_auto_indentation (plugin, editor, insert_line, &parenthesis_indentation);
			set_line_indentation (plugin, editor, insert_line, line_indent, parenthesis_indentation);
			ianjuta_document_end_undo_action (IANJUTA_DOCUMENT(editor), NULL);
		}
	}

	if (g_settings_get_boolean (plugin->settings, PREF_BRACE_AUTOCOMPLETION))
	{
		if (ch == '[' || ch == '(')
		            {
						gchar *prev_char, *next_char;
						IAnjutaIterable *previous, *next, *next_end;

						previous = ianjuta_iterable_clone (iter, NULL);
						ianjuta_iterable_previous (previous, NULL);
						prev_char = ianjuta_editor_get_text (editor, previous, iter, NULL);

						next = ianjuta_iterable_clone (iter, NULL);
						ianjuta_iterable_next (next, NULL);
						next_end = ianjuta_iterable_clone (next, NULL);
						ianjuta_iterable_next (next_end, NULL);
						next_char = ianjuta_editor_get_text (editor, next, next_end, NULL);

						/* If the previous char is a ' we don't have to autocomplete,
						   also we only autocomplete if the next character is white-space
						   a closing bracket, "," or ";" */
						if (*prev_char != '\'' &&
						    (g_ascii_isspace(*next_char) || is_closing_bracket (*next_char) ||
							 *next_char == ',' || *next_char == ';'|| *next_char == '\0'))
						{
							ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (editor), NULL);
							ianjuta_iterable_next (iter, NULL);
							switch (ch)
							{
								case '[':
									       insert_editor_blocked (editor, iter,
									                              "]", plugin);
									       break;
								case '(':
									       insert_editor_blocked (editor, iter,
									                       ")", plugin);
									       break;
								default:
									       break;
							}
							ianjuta_editor_goto_position (editor, iter, NULL);
							ianjuta_document_end_undo_action (IANJUTA_DOCUMENT (editor), NULL);
						}
						g_object_unref (previous);
					}
		            else if (ch == '"' || ch == '\'')
		            {
						gchar *prev_char;
						IAnjutaIterable *previous;

						previous = ianjuta_iterable_clone (iter, NULL);
						ianjuta_iterable_previous (previous, NULL);
						prev_char = ianjuta_editor_get_text (editor, previous, iter, NULL);

						/* First iter*/
						ianjuta_iterable_next (iter, NULL);

						/*
						 * If the character is " we have to decide if we need insert
						 * another " or we have to skip the character
						 */
						if (ch == '"' || ch == '\'')
						{
							/*
							 * Now we have to detect if we want to manage " as a char
							 */
							if (*prev_char != '\'' && *prev_char != '\\')
							{
								gchar *c;

								if (ch == '"')
									c = g_strdup ("\"");
								else c = g_strdup ("'");

								ianjuta_document_begin_undo_action (IANJUTA_DOCUMENT (editor), NULL);
								insert_editor_blocked (editor, iter, c, plugin);
								ianjuta_editor_goto_position (editor, iter, NULL);
								ianjuta_document_end_undo_action (IANJUTA_DOCUMENT (editor), NULL);

								g_free (c);
							}
							g_object_unref (previous);
							g_object_unref (iter);
							return;
						}
						g_object_unref (previous);
					}
	            }
	g_object_unref (iter);
}