void glatex_insert_latex_fontsize(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) { gint size = GPOINTER_TO_INT(gdata); GeanyDocument *doc = NULL; doc = document_get_current(); if (doc != NULL) { if (sci_has_selection(doc->editor->sci)) { gchar *selection; gchar *replacement = NULL; selection = sci_get_selection_contents(doc->editor->sci); replacement = g_strconcat("{",glatex_fontsize_pattern[size], " ", selection, "}", NULL); sci_replace_sel(doc->editor->sci, replacement); g_free(selection); g_free(replacement); } else { sci_start_undo_action(doc->editor->sci); glatex_insert_string(glatex_fontsize_pattern[size], TRUE); glatex_insert_string(" ", TRUE); sci_end_undo_action(doc->editor->sci); } } }
void glatex_bibtex_write_entry(GPtrArray *entry, gint doctype) { gint i; GString *output = NULL; gchar *tmp = NULL; GeanyDocument *doc = NULL; const gchar *eol; doc = document_get_current(); if (doc != NULL) { eol = editor_get_eol_char(doc->editor); } else { eol = "\n"; } /* Adding the doctype to entry */ output = g_string_new("@"); g_string_append(output, glatex_bibtex_types[doctype].latex); g_string_append(output, "{"); g_string_append(output, eol); /* Adding the keywords and values to entry */ for (i = 0; i < GLATEX_BIBTEX_N_ENTRIES; i++) { /* Check whether a field has been marked for being used */ if (g_ptr_array_index (entry, i) != NULL) { /* Check whether a field was only set for being used ... */ if (utils_str_equal(g_ptr_array_index (entry, i), "\0")) { g_string_append(output, glatex_label_entry_keywords[i]); g_string_append(output," = {},"); g_string_append(output, eol); } /* ... or has some real value inside. */ else { g_string_append(output, glatex_label_entry_keywords[i]); g_string_append(output, " = {"); g_string_append(output, g_ptr_array_index(entry, i)); g_string_append(output, "},"); g_string_append(output, eol); } } } g_string_append(output, "}"); g_string_append(output, eol); tmp = g_string_free(output, FALSE); sci_start_undo_action(doc->editor->sci); glatex_insert_string(tmp, FALSE); sci_end_undo_action(doc->editor->sci); g_free(tmp); }
void glatex_insert_latex_format(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) { gint format = GPOINTER_TO_INT(gdata); GeanyDocument *doc = NULL; doc = document_get_current(); if (doc != NULL) { if (sci_has_selection(doc->editor->sci)) { gchar *selection; gchar *replacement = NULL; selection = sci_get_selection_contents(doc->editor->sci); if (format == LATEX_SMALLCAPS && glatex_lowercase_on_smallcaps == TRUE) { gchar *new_selection = NULL; new_selection = g_utf8_strdown(selection, -1); g_free(selection); selection = g_strdup(new_selection); g_free(new_selection); } replacement = g_strconcat(glatex_format_pattern[format],"{", selection, "}", NULL); sci_replace_sel(doc->editor->sci, replacement); g_free(selection); g_free(replacement); } else { sci_start_undo_action(doc->editor->sci); glatex_insert_string(glatex_format_pattern[format], TRUE); glatex_insert_string("{", TRUE); glatex_insert_string("}", FALSE); sci_end_undo_action(doc->editor->sci); } } }
void glatex_bibtex_insert_cite(gchar *reference_name, gchar *option) { gchar *tmp; g_return_if_fail(reference_name != NULL); if (option != NULL) { tmp = g_strconcat("\\cite[", option, "]{", reference_name, "}", NULL); } else { tmp = g_strconcat("\\cite{", reference_name, "}", NULL); } glatex_insert_string(tmp, TRUE); g_free(tmp); }
/* 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); } } }
void glatex_kb_insert_newitem(G_GNUC_UNUSED guint key_id) { g_return_if_fail(document_get_current() != NULL); glatex_insert_string("\\item ", TRUE); }