예제 #1
0
static void
goto_file_line_cb(const gchar * filename, const gchar * line, const gchar * reason)
{
	gint pos;
	gint page;
	GeanyDocument *doc;

	gint line_num = gdbio_atoi((gchar *) line) - 1;
	if (reason)
	{
		msgwin_compiler_add(COLOR_BLUE, "%s", reason);
	}
	doc = document_open_file(filename, FALSE, NULL, NULL);
	if (!(doc && doc->is_valid))
	{
		return;
	}
	page = gtk_notebook_page_num(NOTEBOOK, GTK_WIDGET(doc->editor->sci));
	gtk_notebook_set_current_page(NOTEBOOK, page);
	pos = sci_get_position_from_line(doc->editor->sci, line_num);
	sci_ensure_line_is_visible(doc->editor->sci, line_num);
	while (gtk_events_pending())
	{
		gtk_main_iteration();
	}
	sci_set_current_position(doc->editor->sci, pos, TRUE);
	gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
	gtk_window_present(GTK_WINDOW(geany->main_widgets->window));
}
예제 #2
0
void enclose_text_action (guint key_id)
{
	gint selection_end;
	gchar insert_chars [2] = {0, 0};
	ScintillaObject *sci_obj;

	if (!enclose_enabled)
		return;

	sci_obj = document_get_current ()->editor->sci;

	if (sci_get_selected_text_length (sci_obj) < 2)
		return;

	key_id -= 4;
	selection_end = sci_get_selection_end (sci_obj);

	sci_start_undo_action (sci_obj);
	insert_chars [0] = *enclose_chars [key_id];
	sci_insert_text (sci_obj, sci_get_selection_start (sci_obj), insert_chars);
	insert_chars [0] = *(enclose_chars [key_id] + 1);
	sci_insert_text (sci_obj, selection_end + 1, insert_chars);
	sci_set_current_position (sci_obj, selection_end + 2, TRUE);
	sci_end_undo_action (sci_obj);
}
예제 #3
0
static PyObject *
ZenEditor_replace_content(ZenEditor *self, PyObject *args)
{
	PyObject *result;
	gint sel_start = -1, sel_end = -1, ph_pos;
	gchar *text, *ph, *tmp, *tmp2;
	ScintillaObject *sci;

	print_called();
	py_return_none_if_null(sci = ZenEditor_get_scintilla(self));

	if (PyArg_ParseTuple(args, "s|ii", &text, &sel_start, &sel_end))
	{
		tmp = ZenEditor_replace_caret_placeholder(self->caret_placeholder, text, &ph_pos);
		tmp2 = ZenEditor_replace_range(tmp);
		g_free(tmp);

		if (sel_start == -1 && sel_end == -1)
		{
			/* replace whole editor content */
			sci_set_text(sci, tmp2);
		}
		else if (sel_start != -1 && sel_end == -1)
		{
			/* insert text at sel_start */
			sci_insert_text(sci, sel_start, tmp2);
		}
		else if (sel_start != -1 && sel_end != -1)
		{
			/* replace from sel_start to sel_end */
			sci_set_selection_start(sci, sel_start);
			sci_set_selection_end(sci, sel_end);
			sci_replace_sel(sci, tmp2);
		}
		else
		{
			dbgf("Invalid arguments were supplied.");
			g_free(tmp2);
			Py_RETURN_NONE;
		}

		g_free(tmp2);

		/* Move cursor to first placeholder position, if found */
		if (ph_pos > -1)
			sci_set_current_position(sci, sel_start + ph_pos, TRUE);

	}
	else
	{
		if (PyErr_Occurred())
		{
			PyErr_Print();
			PyErr_Clear();
		}
	}

	Py_RETURN_NONE;
}
예제 #4
0
gboolean on_key_press (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
	gint selection_end;
	gchar insert_chars [4] = {0, 0, 0, 0};
	ScintillaObject *sci_obj;

	if (!auto_enabled)
		return FALSE;

	sci_obj = document_get_current ()->editor->sci;

	if (sci_get_selected_text_length (sci_obj) < 2)
		return FALSE;

	switch (event->keyval)
	{
		case '(':
			insert_chars [0] = '(';
			insert_chars [2] = ')';
			break;
		case '[':
			insert_chars [0] = '[';
			insert_chars [2] = ']';
			break;
		case '{':
			insert_chars [0] = '{';
			insert_chars [2] = '}';
			break;
		case '\'':
			insert_chars [0] = '\'';
			insert_chars [2] = '\'';
			break;
		case '\"':
			insert_chars [0] = '\"';
			insert_chars [2] = '\"';
			break;
        case '`':
            insert_chars [0] = '`';
            insert_chars [2] = '`';
			break;
		default:
			return FALSE;
	}

	selection_end = sci_get_selection_end (sci_obj);

	sci_start_undo_action (sci_obj);
	sci_insert_text (sci_obj, sci_get_selection_start (sci_obj), insert_chars);
	sci_insert_text (sci_obj, selection_end + 1, insert_chars+2);
	sci_set_current_position (sci_obj, selection_end + 2, TRUE);
	sci_end_undo_action (sci_obj);

	return TRUE;
}
예제 #5
0
static PyObject *
Scintilla_set_current_position(Scintilla *self, PyObject *args, PyObject *kwargs)
{
	gint pos, stc = FALSE;
	static gchar *kwlist[] = { "pos", "scroll_to_caret", NULL };

	SCI_RET_IF_FAIL(self);

	if (PyArg_ParseTupleAndKeywords(args, kwargs, "i|i", kwlist, &pos, &stc))
		sci_set_current_position(self->sci, pos, stc);

	Py_RETURN_NONE;
}
예제 #6
0
static PyObject *
ZenEditor_set_caret_pos(ZenEditor *self, PyObject *args)
{
	gint pos;
	ScintillaObject *sci;

	print_called();
	py_return_none_if_null(sci = ZenEditor_get_scintilla(self));

	if (PyArg_ParseTuple(args, "i", &pos))
		sci_set_current_position(sci, pos, TRUE);

	Py_RETURN_NONE;
}
예제 #7
0
static void goto_tag(gboolean definition)
{
	GeanyDocument *doc = document_get_current();

	g_return_if_fail(doc != NULL);

	/* update cursor pos for navigating back afterwards */
	if (!sci_has_selection(doc->editor->sci))
		sci_set_current_position(doc->editor->sci, editor_info.click_pos, FALSE);

	/* use the keybinding callback as it checks for selections as well as current word */
	if (definition)
		keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDEFINITION);
	else
		keybindings_send_command(GEANY_KEY_GROUP_GOTO, GEANY_KEYS_GOTO_TAGDECLARATION);
}
예제 #8
0
static gboolean
improve_indent(
	ScintillaObject *sci,
	GeanyEditor     *editor,
	gint             pos)
{
	gint ch, ch_next;
	gint line;
	gint indent, indent_width;
	gint end_pos;
	if (!ac_info->improved_cbracket_indent)
		return AC_CONTINUE_ACTION;
	ch = char_at(sci, pos - 1);
	if (ch != '{')
		return AC_CONTINUE_ACTION;
	/* if curly bracket completion is enabled - just make indents
	 * but ensure that second "}" exists. If disabled - make indent
	 * and complete second curly bracket */
	ch_next = char_at(sci, pos);
	if (ac_info->cbracket && ch_next != '}')
		return AC_CONTINUE_ACTION;
	line = sci_get_line_from_position(sci, pos);
	indent = sci_get_line_indentation(sci, line);
	indent_width = editor_get_indent_prefs(editor)->width;
	sci_start_undo_action(sci);
	if (ac_info->cbracket)
		SSM(sci, SCI_ADDTEXT, 2, (sptr_t)"\n\n");
	else
		SSM(sci, SCI_ADDTEXT, 3, (sptr_t)"\n\n}");
	if (ac_info->whitesmiths_style)
	{
		sci_set_line_indentation(sci, line,     indent);
		sci_set_line_indentation(sci, line + 1, indent);
		sci_set_line_indentation(sci, line + 2, indent);
	}
	else
	{
		sci_set_line_indentation(sci, line + 1, indent + indent_width);
		sci_set_line_indentation(sci, line + 2, indent);
	}
	/* move to the end of added line */
	end_pos = sci_get_line_end_position(sci, line + 1);
	sci_set_current_position(sci, end_pos, TRUE);
	sci_end_undo_action(sci);
	/* do not alow internal auto-indenter to do the work */
	return AC_STOP_ACTION;
}
예제 #9
0
static void
on_kb_goto_matching_tag (guint key_id)
{
    gint cur_line;
    gint jump_line = 0;
    if(highlightedBrackets[0] != highlightedBrackets[2] && highlightedBrackets[0] != 0){
        GeanyDocument *doc = document_get_current();
        cur_line = sci_get_current_position(doc->editor->sci);
        if(cur_line >= highlightedBrackets[0] && cur_line <= highlightedBrackets[1]){
            jump_line = highlightedBrackets[2];
        }
        else if(cur_line >= highlightedBrackets[2] && cur_line <= highlightedBrackets[3]){
            jump_line = highlightedBrackets[0];
        }
        if(jump_line != 0){
            sci_set_current_position(doc->editor->sci, jump_line, TRUE);
        }
    }
}
예제 #10
0
파일: splitwindow.c 프로젝트: giuspen/geany
static void sync_to_current(ScintillaObject *sci, ScintillaObject *current)
{
    gpointer sdoc;
    gint pos;

    /* set the new sci widget to view the existing Scintilla document */
    sdoc = (gpointer) scintilla_send_message(current, SCI_GETDOCPOINTER, 0, 0);
    scintilla_send_message(sci, SCI_SETDOCPOINTER, 0, (sptr_t) sdoc);

    highlighting_set_styles(sci, edit_window.editor->document->file_type);
    pos = sci_get_current_position(current);
    sci_set_current_position(sci, pos, TRUE);

    /* override some defaults */
    set_line_numbers(sci, geany->editor_prefs->show_linenumber_margin);
    /* marker margin */
    scintilla_send_message(sci, SCI_SETMARGINWIDTHN, 1,
                           scintilla_send_message(current, SCI_GETMARGINWIDTHN, 1, 0));
    if (!geany->editor_prefs->folding)
        scintilla_send_message(sci, SCI_SETMARGINWIDTHN, 2, 0);
}
예제 #11
0
static PyObject *
ZenEditor_create_selection(ZenEditor *self, PyObject *args)
{
	gint sel_start = -1, sel_end = -1;
	ScintillaObject *sci;

	print_called();
	py_return_none_if_null(sci = ZenEditor_get_scintilla(self));

	if (PyArg_ParseTuple(args, "i|i", &sel_start, &sel_end))
	{
		if (sel_end == -1)
			sci_set_current_position(sci, sel_start, TRUE);
		else
		{
			sci_set_selection_start(sci, sel_start);
			sci_set_selection_end(sci, sel_end);
		}
	}

	Py_RETURN_NONE;
}
예제 #12
0
파일: sciwrappers.c 프로젝트: GWRon/geany
/* Set the cursor line without scrolling the view.
 * Use sci_goto_line() to also scroll. */
void sci_set_current_line(ScintillaObject *sci, gint line)
{
	gint pos = sci_get_position_from_line(sci, line);
	sci_set_current_position(sci, pos, FALSE);
}
예제 #13
0
static gboolean
editor_notify_cb(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data)
{
	gint i = 0, val;
	gint old_position = 0;
	gint old_lposition = 0;
	gint old_line = 0;
	gint pos;
	if(NULL == editor || NULL == editor->sci)
		return FALSE;
	if(nt->nmhdr.code == SCN_CHARADDED)
	{
		if('\n' == nt->ch)
			define_format_newline(editor->sci);
	}
	if(nt->nmhdr.code == SCN_UPDATEUI)
	{
		if(g_array_index(lines_stack, gint, 0))
		{
			/* save current position */
			old_line = sci_get_current_line(editor->sci);
			old_lposition = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line);
			old_position = sci_get_current_position(editor->sci);
			sci_start_undo_action(editor->sci);
		}
		while((val = g_array_index(lines_stack, gint, i)))
		{
			i++;
			define_format_line(editor->sci, val - 1);
			dprintf("Removed from stack: %d\n", val);
		}
		if(i > 0)
		{
			sci_end_undo_action(editor->sci);
			g_array_remove_range(lines_stack, 0, i);
			/* restore current position */
			pos = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line);
			sci_set_current_position(editor->sci, old_position + pos - old_lposition, FALSE);
		}
	}
	if(nt->nmhdr.code == SCN_MODIFIED)
	{
		if(nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
		{
			if(nt->modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO))
				return FALSE;
			gint line = sci_get_line_from_position(editor->sci, nt->position) + 1;
			if(sci_get_char_at(editor->sci, get_line_end(editor->sci, line - 1) - 1) == '\\')
			{
				gboolean found = FALSE;
				while((val = g_array_index(lines_stack, gint, i)))
				{
					if(val == line)
					{
						found = TRUE;
						break;
					}
					i++;
				}
				if(!found)
				{
					dprintf("Added line: %d\n", line);
					g_array_append_val(lines_stack, line);
				}
			}
		}
	}
	return FALSE;
}