Ejemplo n.º 1
0
static PyObject *
Editor_get_default_indent_prefs(PyObject *module)
{
	const GeanyIndentPrefs *indent_prefs;
	IndentPrefs *py_prefs;
	indent_prefs = editor_get_indent_prefs(NULL);
	if (indent_prefs != NULL)
	{
		py_prefs = IndentPrefs_create_new_from_geany_indent_prefs((GeanyIndentPrefs *)indent_prefs);
		return (PyObject *) py_prefs;
	}
	Py_RETURN_NONE;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
static GeanyProject *create_project(void)
{
	GeanyProject *project = g_new0(GeanyProject, 1);

	memset(&priv, 0, sizeof priv);
	indentation = *editor_get_indent_prefs(NULL);
	priv.indentation = &indentation;
	project->priv = &priv;

	project->file_patterns = NULL;

	project->long_line_behaviour = 1 /* use global settings */;
	project->long_line_column = editor_prefs.long_line_column;

	app->project = project;
	return project;
}
Ejemplo n.º 4
0
static void init_stash_prefs(void)
{
	StashGroup *group;
	GKeyFile *kf;

	group = stash_group_new("indentation");
	/* copy global defaults */
	indentation = *editor_get_indent_prefs(NULL);
	stash_group_set_use_defaults(group, FALSE);
	add_stash_group(group);

	stash_group_add_spin_button_integer(group, &indentation.width,
		"indent_width", 4, "spin_indent_width_project");
	stash_group_add_radio_buttons(group, (gint*)(gpointer)&indentation.type,
		"indent_type", GEANY_INDENT_TYPE_TABS,
		"radio_indent_spaces_project", GEANY_INDENT_TYPE_SPACES,
		"radio_indent_tabs_project", GEANY_INDENT_TYPE_TABS,
		"radio_indent_both_project", GEANY_INDENT_TYPE_BOTH,
		NULL);
	/* This is a 'hidden' pref for backwards-compatibility */
	stash_group_add_integer(group, &indentation.hard_tab_width,
		"indent_hard_tab_width", 8);
	stash_group_add_toggle_button(group, &indentation.detect_type,
		"detect_indent", FALSE, "check_detect_indent_type_project");
	stash_group_add_toggle_button(group, &indentation.detect_width,
		"detect_indent_width", FALSE, "check_detect_indent_width_project");
	stash_group_add_combo_box(group, (gint*)(gpointer)&indentation.auto_indent_mode,
		"indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project");

	group = stash_group_new("file_prefs");
	stash_group_add_toggle_button(group, &priv.final_new_line,
		"final_new_line", file_prefs.final_new_line, "check_new_line1");
	stash_group_add_toggle_button(group, &priv.ensure_convert_new_lines,
		"ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1");
	stash_group_add_toggle_button(group, &priv.strip_trailing_spaces,
		"strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1");
	stash_group_add_toggle_button(group, &priv.replace_tabs,
		"replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1");
	add_stash_group(group);
	/* apply defaults */
	kf = g_key_file_new();
	stash_group_load_from_key_file(group, kf);
	g_key_file_free(kf);
}
Ejemplo n.º 5
0
/**
 * \brief Called by Geany to initialize the plugin.
 * \note data is the same as geany_data.
 */
void plugin_init(GeanyData *data)
{
    const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(NULL);

    gms_hnd = gms_new(geany->main_widgets->window,
                    data->interface_prefs->editor_font ,
                    iprefs->width,
					geany->app->configdir
                    ) ;

    /* Add an item to the Tools menu */
    gms_item = gtk_menu_item_new_with_mnemonic(_("_Mini-Script"));
    gtk_widget_show(gms_item);
    gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), gms_item);
    g_signal_connect(gms_item, "activate", G_CALLBACK(item_activate), NULL);

    /* make the menu item sensitive only when documents are open */
    ui_add_document_sensitive(gms_item);

}
Ejemplo n.º 6
0
/* if type == -1 then we will try to autodetect the type */
void glatex_insert_environment(const gchar *environment, gint type)
{
	GeanyDocument *doc = NULL;

	doc = document_get_current();

	/* Only do anything if it is realy needed to */
	if (doc != NULL && environment != NULL)
	{
		if (sci_has_selection(doc->editor->sci))
		{
			gchar *selection  = NULL;
			gchar *replacement = NULL;
			selection = sci_get_selection_contents(doc->editor->sci);

			sci_start_undo_action(doc->editor->sci);
			if (utils_str_equal(environment, "block") == TRUE)
			{
				replacement = g_strconcat("\\begin{", environment, "}{}\n",
							  selection, "\n\\end{", environment, "}\n", NULL);
			}
			else
			{
				replacement = g_strconcat("\\begin{", environment, "}\n",
							  selection, "\n\\end{", environment, "}\n", NULL);
			}
			sci_replace_sel(doc->editor->sci, replacement);
			sci_end_undo_action(doc->editor->sci);
			g_free(selection);
			g_free(replacement);

		}
		else
		{
			gint indent, pos;
			GString *tmpstring = NULL;
			gchar *tmp = NULL;
			static const GeanyIndentPrefs *indention_prefs = NULL;

			if (type == -1)
			{
				gint i;

				/* First, we check whether we have a known list over here
				 * an reset type to fit new value*/
				for (i = 0; i < GLATEX_LIST_END; i++)
				{
					if (utils_str_equal(glatex_list_environments[i], environment) == TRUE)
					{
						type = GLATEX_ENVIRONMENT_TYPE_LIST;
						break;
					}
				}
			}
			pos = sci_get_current_position(doc->editor->sci);

			sci_start_undo_action(doc->editor->sci);

			tmpstring = g_string_new("\\begin{");
			g_string_append(tmpstring, environment);

			if (utils_str_equal(environment, "block") == TRUE)
			{
				g_string_append(tmpstring, "}{}");
			}
			else
			{
				g_string_append(tmpstring, "}");
			}
			g_string_append(tmpstring, "\n");


			if (type == GLATEX_ENVIRONMENT_TYPE_LIST)
			{
				g_string_append(tmpstring, "\t\\item ");
			}

			tmp = g_string_free(tmpstring, FALSE);
			glatex_insert_string(tmp, TRUE);
			g_free(tmp);

			indent = sci_get_line_indentation(doc->editor->sci,
				sci_get_line_from_position(doc->editor->sci, pos));

			tmp = g_strdup_printf("\n\\end{%s}", environment);
			glatex_insert_string(tmp, FALSE);
			g_free(tmp);

			indention_prefs = editor_get_indent_prefs(doc->editor);
			if (type == GLATEX_ENVIRONMENT_TYPE_LIST)
			{
				sci_set_line_indentation(doc->editor->sci,
					sci_get_current_line(doc->editor->sci),
					indent + indention_prefs->width);
			}
			sci_set_line_indentation(doc->editor->sci,
				sci_get_current_line(doc->editor->sci) + 1, indent);
			sci_end_undo_action(doc->editor->sci);
		}
	}
}
Ejemplo n.º 7
0
static PyObject *
Editor_get_property(Editor *self, const gchar *prop_name)
{
	g_return_val_if_fail(self != NULL, NULL);
	g_return_val_if_fail(prop_name != NULL, NULL);

	if (!self->editor)
	{
		PyErr_SetString(PyExc_RuntimeError,
			"Editor instance not initialized properly");
		return NULL;
	}

	if (g_str_equal(prop_name, "eol_char"))
		return PyString_FromString(editor_get_eol_char(self->editor));
	else if (g_str_equal(prop_name, "eol_char_name"))
		return PyString_FromString(editor_get_eol_char_name(self->editor));
	else if (g_str_equal(prop_name, "indent_prefs"))
	{
		const GeanyIndentPrefs *indent_prefs;
		IndentPrefs *py_prefs;
		indent_prefs = editor_get_indent_prefs(self->editor);
		if (indent_prefs)
		{
			py_prefs = IndentPrefs_create_new_from_geany_indent_prefs(
							(GeanyIndentPrefs *) indent_prefs);
			return (PyObject *) py_prefs;
		}
		Py_RETURN_NONE;
	}
	else if (g_str_equal(prop_name, "auto_indent"))
	{
		if (self->editor->auto_indent)
			Py_RETURN_TRUE;
		else
			Py_RETURN_FALSE;
	}
	else if (g_str_equal(prop_name, "document"))
	{
		PyObject *py_doc;
		py_doc = (PyObject *) Document_create_new_from_geany_document(
									self->editor->document);
		if (py_doc && py_doc != Py_None)
			Py_RETURN_NONE;
		return py_doc;
	}
	else if (g_str_equal(prop_name, "line_breaking"))
	{
		if (self->editor->line_breaking)
			Py_RETURN_TRUE;
		else
			Py_RETURN_FALSE;
	}
	else if (g_str_equal(prop_name, "line_wrapping"))
	{
		if (self->editor->line_wrapping)
			Py_RETURN_TRUE;
		else
			Py_RETURN_FALSE;
	}
	else if (g_str_equal(prop_name, "scintilla"))
	{
		Scintilla *sci;
		sci = Scintilla_create_new_from_scintilla(self->editor->sci);
		if (!sci)
			Py_RETURN_NONE;
		return (PyObject *) sci;
	}
	else if (g_str_equal(prop_name, "scroll_percent"))
		return PyFloat_FromDouble((gdouble) self->editor->scroll_percent);

	PyErr_SetString(PyExc_AttributeError, "can't get property");
	Py_RETURN_NONE;
}