static void on_comments_function_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); gchar *text; const gchar *cur_tag = NULL; gint line = -1, pos = 0; if (doc == NULL || doc->file_type == NULL) { ui_set_statusbar(FALSE, _("Please set the filetype for the current file before using this function.")); return; } /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line * returns the current position, so it should be safe */ line = symbols_get_current_function(doc, &cur_tag); pos = sci_get_position_from_line(doc->editor->sci, line); text = templates_get_template_function(doc, cur_tag); sci_start_undo_action(doc->editor->sci); sci_insert_text(doc->editor->sci, pos, text); sci_end_undo_action(doc->editor->sci); g_free(text); }
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); }
static void reindent (GeanyDocument *doc, GrindIndenter *indenter) { if (DOC_VALID (doc)) { int start; int end; ScintillaObject *sci = doc->editor->sci; if (sci_has_selection (sci)) { start = sci_get_line_from_position (sci, sci_get_selection_start (sci)); end = sci_get_line_from_position (sci, sci_get_selection_end (sci)); } else { start = 0; end = sci_get_line_count (sci); } if (start != end) { g_debug ("Using indenter \"%s\" by \"%s\"", grind_indenter_get_name (indenter), grind_indenter_get_author (indenter)); sci_start_undo_action (sci); if (grind_indenter_indent (indenter, doc, sci_get_position_from_line (sci, start), sci_get_line_end_position (sci, end))) { msgwin_status_add ("Reindented \"%s\"", DOC_FILENAME (doc)); } sci_end_undo_action (sci); } } }
static PyObject * Scintilla_start_undo_action(Scintilla *self) { SCI_RET_IF_FAIL(self); sci_start_undo_action(self->sci); Py_RETURN_NONE; }
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); }
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; }
static void lipsum_activated(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { GeanyDocument *doc = NULL; /* Setting default length to 1500 characters */ gdouble value = 1500; doc = document_get_current(); if (doc != NULL && dialogs_show_input_numeric(_("Lipsum-Generator"), _("Enter the length of Lipsum text here"), &value, 1, 5000, 1)) { int tmp = 0; int x = 0; int i = 0; int missing = 0; /* Checking what we have */ tmp = strlen(lipsum); if (tmp > value) { x = 0; missing = value - (x * tmp); } else if (tmp == (int)value) { x = 1; } else if (tmp > 0) { x = value / tmp; missing = value - (x * tmp); } sci_start_undo_action(doc->editor->sci); /* Insert lipsum snippet as often as needed ... */ if (missing > 0) { gchar *missing_text = g_strndup(lipsum, missing); insert_string(doc, missing_text); g_free(missing_text); } for (i = 0; i < x; i++) { insert_string(doc, lipsum); } sci_end_undo_action(doc->editor->sci); } }
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; }
void glatex_structure_lvlup(void) { gint i; GeanyDocument *doc = NULL; gchar *tmp = NULL; GString *haystack = NULL; doc = document_get_current(); if (doc == NULL) return; if (! sci_has_selection(doc->editor->sci)) return; sci_start_undo_action(doc->editor->sci); tmp = sci_get_selection_contents(doc->editor->sci); haystack = g_string_new(tmp); g_free(tmp); tmp = NULL; for (i = 0; i < GLATEX_STRUCTURE_N_LEVEL; i++) { if (utils_string_replace_all (haystack, glatex_structure_values[i], glatex_structure_values[glatex_structure_rotate(FALSE, i)] ) > 0) { tmp = g_string_free(haystack, FALSE); haystack = NULL; sci_replace_sel(doc->editor->sci, tmp); g_free(tmp); sci_end_undo_action(doc->editor->sci); break; } } if (haystack != NULL) g_string_free(haystack, TRUE); }
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 geanypg_write_file(FILE * file) { #define BUFSIZE 2048 unsigned long size; char buffer[BUFSIZE] = {0}; GeanyDocument * doc = document_get_current(); sci_start_undo_action(doc->editor->sci); if (sci_has_selection(doc->editor->sci)) { /* replace selected text * clear selection, cursor should be at the end or beginneng of the selection */ scintilla_send_message(doc->editor->sci, SCI_REPLACESEL, 0, (sptr_t)""); while ((size = fread(buffer, 1, BUFSIZE, file))) /* add at the cursor */ scintilla_send_message(doc->editor->sci, SCI_ADDTEXT, (uptr_t) size, (sptr_t) buffer); } else { /* replace complete document */ scintilla_send_message(doc->editor->sci, SCI_CLEARALL, 0, 0); while ((size = fread(buffer, 1, BUFSIZE, file))) scintilla_send_message(doc->editor->sci, SCI_APPENDTEXT, (uptr_t) size, (sptr_t) buffer); } sci_end_undo_action(doc->editor->sci); #undef BUFSIZE }
static void insert_numbers(gboolean *cancel) { /* editor */ ScintillaObject *sci = document_get_current()->editor->sci; gint xinsert = sci_point_x_from_position(sci, start_pos); gint xend = sci_point_x_from_position(sci, end_pos); gint *line_pos = g_new(gint, end_line - start_line + 1); gint line, i; /* generator */ gint64 start = start_value; gint64 value; unsigned count = 0; size_t prefix_len = 0; int plus = 0, minus; size_t length, lend; char pad, aax; gchar *buffer; if (xend < xinsert) xinsert = xend; ui_progress_bar_start(_("Counting...")); /* lines shorter than the current selection are skipped */ for (line = start_line, i = 0; line <= end_line; line++, i++) { if (sci_point_x_from_position(sci, scintilla_send_message(sci, SCI_GETLINEENDPOSITION, line, 0)) >= xinsert) { line_pos[i] = sci_get_pos_at_line_sel_start(sci, line) - sci_get_position_from_line(sci, line); count++; } else line_pos[i] = -1; if (cancel && i % 2500 == 0) { update_display(); if (*cancel) { ui_progress_bar_stop(); g_free(line_pos); return; } } } switch (base_value * base_prefix) { case 8 : prefix_len = 1; break; case 16 : prefix_len = 2; break; case 10 : plus++; } value = start + (count - 1) * step_value; minus = start < 0 || value < 0; lend = plus || (pad_zeros ? minus : value < 0); while (value /= base_value) lend++; value = start; length = plus || (pad_zeros ? minus : value < 0); while (value /= base_value) length++; length = prefix_len + (length > lend ? length : lend) + 1; buffer = g_new(gchar, length + 1); buffer[length] = '\0'; pad = pad_zeros ? '0' : ' '; aax = (lower_case ? 'a' : 'A') - 10; gtk_progress_bar_set_text(GTK_PROGRESS_BAR(geany->main_widgets->progressbar), _("Preparing...")); update_display(); sci_start_undo_action(sci); sci_replace_sel(sci, ""); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(geany->main_widgets->progressbar), _("Inserting...")); for (line = start_line, i = 0; line <= end_line; line++, i++) { gchar *beg, *end; gint insert_pos; if (line_pos[i] < 0) continue; beg = buffer; end = buffer + length; value = ABS(start); do { unsigned digit = value % base_value; *--end = digit + (digit < 10 ? '0' : aax); } while (value /= base_value); if (pad_zeros) { if (start < 0) *beg++ = '-'; else if (plus) *beg++ = '+'; else if (minus) *beg++ = ' '; memcpy(beg, "0x", prefix_len); beg += prefix_len; } else { if (start < 0) *--end = '-'; else if (plus) *--end = '+'; end -= prefix_len; memcpy(end, "0x", prefix_len); } memset(beg, pad, end - beg); insert_pos = sci_get_position_from_line(sci, line) + line_pos[i]; sci_insert_text(sci, insert_pos, buffer); start += step_value; if (cancel && i % 1000 == 0) { update_display(); if (*cancel) { scintilla_send_message(sci, SCI_GOTOPOS, insert_pos + length, 0); break; } } } sci_end_undo_action(sci); g_free(buffer); g_free(line_pos); ui_progress_bar_stop(); }
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; }
/* 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); } } }
static void shift_left_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_before; gint txt_len; gint startpos; gint endpos; gint startline; gint endline; gint line_iter; gint linepos; gint linelen; gint startcol; gint endcol; gint i; gint n_spaces; gchar *spaces; ScintillaObject *sci; /* get a pointer to the scintilla object */ sci = document_get_current()->editor->sci; if (sci_has_selection(sci)){ startpos = sci_get_selection_start(sci); endpos = sci_get_selection_end(sci); /* sanity check -- we dont care which way the block was selected */ if(startpos > endpos){ i = endpos; endpos = startpos; startpos = i; } startline = sci_get_line_from_position(sci, startpos); /* Setting also start point for 1st line */ linepos = sci_get_position_from_line(sci, startline); endline = sci_get_line_from_position(sci, endpos); /* normal mode */ if(startline == endline){ /* get the text in question */ txt_len = endpos - startpos; txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_before = sci_get_char_at(sci, startpos - 1); /* set up new text buf */ (void) g_sprintf(txt, "%s%c", txt_i, char_before); /* start undo */ sci_start_undo_action(sci); /* put the new text in */ sci_set_selection_start(sci, startpos - 1); sci_replace_sel(sci, txt); /* select the right bit again */ sci_set_selection_start(sci, startpos - 1); sci_set_selection_end(sci, endpos - 1); /* end undo */ sci_end_undo_action(sci); g_free(txt); g_free(txt_i); } /* rectangle mode (we hope!) */ else{ startcol = sci_get_col_from_position(sci, startpos); endcol = sci_get_col_from_position(sci, endpos); /* return early for the trivial case */ if(startcol == 0 || startcol == endcol){ return; } /* start undo */ sci_start_undo_action(sci); for(line_iter = startline; line_iter <= endline; line_iter++){ linepos = sci_get_position_from_line(sci, line_iter); linelen = sci_get_line_length(sci, line_iter); /* do we need to do something */ if(linelen >= startcol - 1 ){ /* if between the two columns */ /* pad to the end first */ if(linelen <= endcol){ /* bung in some spaces -- sorry, I dont like tabs */ n_spaces = endcol - linelen + 1; spaces = g_malloc(sizeof(gchar) * (n_spaces + 1)); for(i = 0; i < n_spaces; i++){ spaces[i] = ' '; } spaces[i] = '\0'; sci_insert_text(sci, linepos + linelen - 1, spaces); g_free(spaces); } /* now move the text itself */ sci_set_selection_mode(sci, 0); sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol); txt_len = sci_get_selected_text_length(sci); txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_before = sci_get_char_at(sci, linepos + startcol - 1); /* set up new text buf */ (void) g_sprintf(txt, "%s%c", txt_i, char_before); /* put the new text in */ sci_set_selection_start(sci, linepos + startcol - 1); sci_replace_sel(sci, txt); g_free(txt); g_free(txt_i); } } /* put the selection box back */ /* here we rely upon the last result of linepos */ sci_set_selection_mode(sci, 1); sci_set_selection_start(sci, startpos - 1); sci_set_selection_end(sci, linepos + endcol - 1); /* end undo action */ sci_end_undo_action(sci); } } }
static void shift_right_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata){ gchar *txt; gchar *txt_i; gchar char_after; gint txt_len; gint startpos; gint endpos; gint startline; gint endline; gint line_iter; gint linepos; gint linelen; gint startcol; gint endcol; gint i; ScintillaObject *sci; /* get a pointer to the scintilla object */ sci = document_get_current()->editor->sci; if (sci_has_selection(sci)){ startpos = sci_get_selection_start(sci); endpos = sci_get_selection_end(sci); /* sanity check -- we dont care which way the block was selected */ if(startpos > endpos){ i = endpos; endpos = startpos; startpos = i; } startline = sci_get_line_from_position(sci, startpos); linepos = sci_get_position_from_line(sci, startline); endline = sci_get_line_from_position(sci, endpos); /* normal mode */ if(startline == endline){ /* get the text in question */ txt_len = endpos - startpos; txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_after = sci_get_char_at(sci, endpos); /* set up new text buf */ (void) g_sprintf(txt, "%c%s", char_after, txt_i); /* start undo */ sci_start_undo_action(sci); /* put the new text in */ sci_set_selection_end(sci, endpos + 1); sci_replace_sel(sci, txt); /* select the right bit again */ sci_set_selection_start(sci, startpos + 1); sci_set_selection_end(sci, endpos + 1); /* end undo */ sci_end_undo_action(sci); g_free(txt); g_free(txt_i); } /* rectangle mode (we hope!) */ else{ startcol = sci_get_col_from_position(sci, startpos); endcol = sci_get_col_from_position(sci, endpos); /* start undo */ sci_start_undo_action(sci); for(line_iter = startline; line_iter <= endline; line_iter++){ linepos = sci_get_position_from_line(sci, line_iter); linelen = sci_get_line_length(sci, line_iter); /* do we need to do something */ if(linelen >= startcol - 1 ){ /* if between the two columns or at the end */ /* add in a space */ if(linelen <= endcol || linelen - 1 == endcol){ txt = g_malloc(sizeof(gchar) * 2); sprintf(txt, " "); sci_insert_text(sci, linepos + startcol, txt); g_free(txt); } else{ /* move the text itself */ sci_set_selection_mode(sci, 0); sci_set_selection_start(sci, linepos + startcol); sci_set_selection_end(sci, linepos + endcol); txt_len = sci_get_selected_text_length(sci); txt_i = g_malloc(txt_len + 1); txt = g_malloc(txt_len + 2); sci_get_selected_text(sci, txt_i); char_after = sci_get_char_at(sci, linepos + endcol); /* set up new text buf */ (void) g_sprintf(txt, "%c%s", char_after, txt_i); /* put the new text in */ sci_set_selection_end(sci, linepos + endcol + 1); sci_replace_sel(sci, txt); g_free(txt); g_free(txt_i); } } } /* put the selection box back */ /* here we rely upon the last result of linepos */ sci_set_selection_mode(sci, 1); sci_set_selection_start(sci, startpos + 1); sci_set_selection_end(sci, linepos + endcol + 1); /* end undo action */ sci_end_undo_action(sci); } } }
static gboolean handle_backspace( AutocloseUserData *data, ScintillaObject *sci, gchar ch, gchar *ch_left, gchar *ch_right, GdkEventKey *event, gint indent_width) { gint pos = sci_get_current_position(sci); gint end_pos; gint line_start, line_end, line; gint i; if (!ac_info->delete_pairing_brace) return AC_CONTINUE_ACTION; ch = char_at(sci, pos - 1); if (!check_chars(sci, ch, ch_left, ch_right)) return AC_CONTINUE_ACTION; if (event->state & GDK_SHIFT_MASK) { if ((ch_left[0] == ch || ch_right[0] == ch) && ac_info->bcksp_remove_pair) { end_pos = sci_find_matching_brace(sci, pos - 1); if (-1 == end_pos) return AC_CONTINUE_ACTION; sci_start_undo_action(sci); line_start = sci_get_line_from_position(sci, pos); line_end = sci_get_line_from_position(sci, end_pos); SSM(sci, SCI_DELETERANGE, end_pos, 1); if (end_pos < pos) pos--; SSM(sci, SCI_DELETERANGE, pos - 1, 1); /* remove indentation magick */ if (char_is_curly_bracket(ch)) { if (line_start == line_end) goto final; if (line_start > line_end) { line = line_end; line_end = line_start; line_start = line; } if (blank_line(sci, line_start)) { delete_line(sci, line_start); line_end--; } else line_start++; if (blank_line(sci, line_end)) delete_line(sci, line_end); line_end--; /* unindent */ for (i = line_start; i <= line_end; i++) { unindent_line(sci, i, indent_width); } } final: sci_end_undo_action(sci); return AC_STOP_ACTION; }