void indent_multi_line_indent(GtkTextBuffer *buffer) { GtkTextIter start_iter, end_iter, iter; gint start_line, end_line, i; gboolean pos; gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter); start_line = gtk_text_iter_get_line(&start_iter); end_line = gtk_text_iter_get_line(&end_iter); gtk_text_buffer_get_iter_at_mark(buffer, &iter, gtk_text_buffer_get_insert(buffer)); pos = gtk_text_iter_equal(&iter, &start_iter); for (i = start_line; i < end_line; i++) { gtk_text_buffer_get_iter_at_line(buffer, &iter, i); gtk_text_buffer_place_cursor(buffer, &iter); g_signal_emit_by_name(G_OBJECT(buffer), "begin-user-action"); gtk_text_buffer_insert(buffer, &iter, "\t", 1); g_signal_emit_by_name(G_OBJECT(buffer), "end-user-action"); undo_set_sequency(TRUE); } undo_set_sequency(FALSE); gtk_text_buffer_get_iter_at_line(buffer, &start_iter, start_line); gtk_text_buffer_get_iter_at_line(buffer, &end_iter, end_line); if (pos) { gtk_text_buffer_place_cursor(buffer, &end_iter); gtk_text_buffer_move_mark_by_name(buffer, "insert", &start_iter); } else { gtk_text_buffer_place_cursor(buffer, &start_iter); gtk_text_buffer_move_mark_by_name(buffer, "insert", &end_iter); } }
gboolean undo_redo_real(GtkTextBuffer *buffer) { GtkTextIter start_iter, end_iter; UndoInfo *ri; if (g_list_length(redo_list)) { // undo_block_signal(buffer); ri = g_list_last(redo_list)->data; gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, ri->start); switch (ri->command) { case INS: gtk_text_buffer_insert(buffer, &start_iter, ri->str, -1); break; default: gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, ri->end); gtk_text_buffer_delete(buffer, &start_iter, &end_iter); } undo_list = g_list_append(undo_list, ri); redo_list = g_list_delete_link(redo_list, g_list_last(redo_list)); DV(g_print("cb_edit_redo: undo left = %d, redo left = %d\n", g_list_length(undo_list), g_list_length(redo_list))); // undo_unblock_signal(buffer); if (ri->seq) { undo_set_sequency(TRUE); return TRUE; } if (!g_list_length(redo_list)) gtk_widget_set_sensitive(redo_w, FALSE); gtk_widget_set_sensitive(undo_w, TRUE); gtk_text_buffer_place_cursor(buffer, &start_iter); scroll_to_cursor(buffer, 0.05); } undo_check_modified_step(buffer); return FALSE; }
void indent_multi_line_unindent(GtkTextBuffer *buffer) { GtkTextIter start_iter, end_iter, iter; gint start_line, end_line, i, len; gboolean pos; gchar *ind; gtk_text_buffer_get_selection_bounds(buffer, &start_iter, &end_iter); start_line = gtk_text_iter_get_line(&start_iter); end_line = gtk_text_iter_get_line(&end_iter); gtk_text_buffer_get_iter_at_mark(buffer, &iter, gtk_text_buffer_get_insert(buffer)); pos = gtk_text_iter_equal(&iter, &start_iter); i = start_line; do { ind = compute_indentation(buffer, NULL, i); if (ind && strlen(ind)) { len = compute_indent_offset_length(ind); gtk_text_buffer_get_iter_at_line(buffer, &start_iter, i); gtk_text_buffer_place_cursor(buffer, &start_iter); end_iter = start_iter; gtk_text_iter_forward_chars(&end_iter, len); gtk_text_buffer_move_mark_by_name(buffer, "insert", &end_iter); g_signal_emit_by_name(G_OBJECT(buffer), "begin-user-action"); gtk_text_buffer_delete(buffer, &start_iter, &end_iter); g_signal_emit_by_name(G_OBJECT(buffer), "end-user-action"); undo_set_sequency(TRUE); g_free(ind); } i++; } while (i < end_line); undo_set_sequency(FALSE); gtk_text_buffer_get_iter_at_line(buffer, &start_iter, start_line); gtk_text_buffer_get_iter_at_line(buffer, &end_iter, end_line); if (pos) { gtk_text_buffer_place_cursor(buffer, &end_iter); gtk_text_buffer_move_mark_by_name(buffer, "insert", &start_iter); } else { gtk_text_buffer_place_cursor(buffer, &start_iter); gtk_text_buffer_move_mark_by_name(buffer, "insert", &end_iter); } }
static gint document_replace_real(GtkWidget *textview) { GtkTextIter iter, match_start, match_end, rep_start; GtkTextMark *mark_init = NULL; gboolean res; gint num = 0, offset; GtkWidget *q_dialog = NULL; GtkSourceSearchFlags search_flags = GTK_SOURCE_SEARCH_VISIBLE_ONLY | GTK_SOURCE_SEARCH_TEXT_ONLY; GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); if (!match_case) search_flags = search_flags | GTK_SOURCE_SEARCH_CASE_INSENSITIVE; if (replace_all) { gtk_text_buffer_get_iter_at_mark(textbuffer, &iter, gtk_text_buffer_get_insert(textbuffer)); mark_init = gtk_text_buffer_create_mark(textbuffer, NULL, &iter, FALSE); gtk_text_buffer_get_start_iter(textbuffer, &iter); gtk_text_buffer_get_end_iter(textbuffer, &match_end); // gtk_text_buffer_remove_tag_by_name(textbuffer, // "replaced", &iter, &match_end); gtk_text_buffer_remove_all_tags(textbuffer, &iter, &match_end); } else { hlight_searched_strings(textbuffer, string_find); hlight_toggle_searched(textbuffer); } do { if (replace_all) { res = gtk_source_iter_forward_search( &iter, string_find, search_flags, &match_start, &match_end, NULL); if (res) { gtk_text_buffer_place_cursor(textbuffer, &match_start); gtk_text_buffer_move_mark_by_name(textbuffer, "insert", &match_end); gtk_text_buffer_get_iter_at_mark( textbuffer, &iter, gtk_text_buffer_get_insert(textbuffer)); } } else // res = document_search_real(textview, 0); res = document_search_real(textview, 2); if (res) { if (!replace_all) { if (num == 0 && q_dialog == NULL) q_dialog = create_dialog_message_question( gtk_widget_get_toplevel(textview), _("Replace?")); #if GTK_CHECK_VERSION(2, 10, 0) GtkTextIter ins,bou; gtk_text_buffer_get_selection_bounds(textbuffer, &ins, &bou); #endif switch (gtk_dialog_run(GTK_DIALOG(q_dialog))) { case GTK_RESPONSE_YES: #if GTK_CHECK_VERSION(2, 10, 0) gtk_text_buffer_select_range(textbuffer, &ins, &bou); #endif break; case GTK_RESPONSE_NO: continue; // case GTK_RESPONSE_CANCEL: default: res = 0; if (num == 0) num = -1; continue; } } gtk_text_buffer_delete_selection(textbuffer, TRUE, TRUE); if (strlen(string_replace)) { gtk_text_buffer_get_iter_at_mark( textbuffer, &rep_start, gtk_text_buffer_get_insert(textbuffer)); offset = gtk_text_iter_get_offset(&rep_start); undo_set_sequency(TRUE); g_signal_emit_by_name(G_OBJECT(textbuffer), "begin-user-action"); gtk_text_buffer_insert_at_cursor(textbuffer, string_replace, strlen(string_replace)); g_signal_emit_by_name(G_OBJECT(textbuffer), "end-user-action"); gtk_text_buffer_get_iter_at_mark( textbuffer, &iter, gtk_text_buffer_get_insert(textbuffer)); gtk_text_buffer_get_iter_at_offset(textbuffer, &rep_start, offset); gtk_text_buffer_apply_tag_by_name(textbuffer, "replaced", &rep_start, &iter); } else gtk_text_buffer_get_iter_at_mark( textbuffer, &iter, gtk_text_buffer_get_insert(textbuffer)); num++; /* if (replace_all) undo_set_sequency(TRUE); else undo_set_sequency(FALSE);*/ undo_set_sequency(replace_all); } } while (res); if (!hlight_check_searched()) hlight_toggle_searched(textbuffer); if (q_dialog) gtk_widget_destroy(q_dialog); /* if (strlen(string_replace)) { replace_mode = TRUE; hlight_searched_strings(textbuffer, string_replace); } */ if (replace_all) { gtk_text_buffer_get_iter_at_mark(textbuffer, &iter, mark_init); gtk_text_buffer_place_cursor(textbuffer, &iter); run_dialog_message(gtk_widget_get_toplevel(textview), GTK_MESSAGE_INFO, _("%d strings replaced"), num); undo_set_sequency(FALSE); } return num; }
static void undo_create_undo_info(GtkTextBuffer *buffer, gchar command, gint start, gint end) { GtkTextIter start_iter, end_iter; gboolean seq_flag = FALSE; gchar *str; gint keyval = get_current_keyval(); gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, start); gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, end); str = gtk_text_buffer_get_text(buffer, &start_iter, &end_iter, FALSE); if (undo_gstr->len) { if ((end - start == 1) && (command == ui_tmp->command)) { switch (keyval) { case GDK_BackSpace: if (end == ui_tmp->start) seq_flag = TRUE; break; case GDK_Delete: if (start == ui_tmp->start) seq_flag = TRUE; break; case GDK_Tab: case GDK_space: if (start == ui_tmp->end) seq_flag = TRUE; break; default: if (start == ui_tmp->end) if (keyval && keyval < 0xF000) switch (prev_keyval) { case GDK_Return: case GDK_Tab: case GDK_space: break; default: seq_flag = TRUE; } } } if (seq_flag) { switch (command) { case BS: undo_gstr = g_string_prepend(undo_gstr, str); ui_tmp->start--; break; default: undo_gstr = g_string_append(undo_gstr, str); ui_tmp->end++; } redo_list = undo_clear_info_list(redo_list); prev_keyval = keyval; gtk_widget_set_sensitive(undo_w, TRUE); gtk_widget_set_sensitive(redo_w, FALSE); return; } undo_append_undo_info(buffer, ui_tmp->command, ui_tmp->start, ui_tmp->end, g_strdup(undo_gstr->str)); undo_gstr = g_string_erase(undo_gstr, 0, -1); } if (!keyval && prev_keyval) undo_set_sequency(TRUE); if (end - start == 1 && ((keyval && keyval < 0xF000) || keyval == GDK_BackSpace || keyval == GDK_Delete || keyval == GDK_Tab)) { ui_tmp->command = command; ui_tmp->start = start; ui_tmp->end = end; undo_gstr = g_string_erase(undo_gstr, 0, -1); g_string_append(undo_gstr, str); } else undo_append_undo_info(buffer, command, start, end, g_strdup(str)); redo_list = undo_clear_info_list(redo_list); prev_keyval = keyval; clear_current_keyval(); // keyevent_setval(0); gtk_widget_set_sensitive(undo_w, TRUE); gtk_widget_set_sensitive(redo_w, FALSE); }
static void dnd_drag_data_recieved_handler(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time) { static gboolean flag_called_once = FALSE; gchar **files; gchar *filename; gchar *comline; gint i = 0, j = 0; gchar *filename_sh; gchar **strs; #ifdef ENABLE_CSDI j = 1; #endif DV(g_print("DND start!\n")); #if GTK_CHECK_VERSION(2, 10, 0) if (g_strcasecmp(gdk_atom_name(context->targets->data), "GTK_TEXT_BUFFER_CONTENTS") != 0) { #else if (info != TARGET_SELF) { #endif if (flag_called_once) { flag_called_once = FALSE; g_signal_stop_emission_by_name(widget, "drag_data_received"); DV(g_print("second drop signal killed.\n")); return; } else flag_called_once = TRUE; } DV({ g_print("info = %d\n", info); g_print("time = %d\n", time); g_print("context->protocol = %d\n", context->protocol); g_print("context->is_source = %d\n", context->is_source); g_print("context->targets = %d\n", g_list_length(context->targets)); g_print("context->target = %s\n", gdk_atom_name(context->targets->data)); /* g_print("context->target = %s\n", gdk_atom_name(context->targets->next->data)); g_print("context->target = %s\n", gdk_atom_name(context->targets->next->next->data)); g_print("context->actions = %d\n", context->actions); g_print("context->suggested_action = %d\n", context->suggested_action); g_print("context->action = %d\n", context->action); g_print("selection_data->selection = %s\n", gdk_atom_name(selection_data->selection)); g_print("selection_data->target = %s\n", gdk_atom_name(selection_data->target)); */ g_print("selection_data->type = %s\n", gdk_atom_name(selection_data->type)); g_print("selection_data->format = %d\n", selection_data->format); g_print("selection_data->length = %d\n", selection_data->length); g_print("%s\n", selection_data->data); }); if (selection_data->data && info == TARGET_URI_LIST) { files = g_strsplit((gchar *)selection_data->data, "\n" , -1); while (files[i]) { if (strlen(files[i]) == 0) break; filename = g_strstrip(parse_file_uri(files[i])); if (i + j == 0) dnd_open_first_file(filename); else { if (i + j == 1) save_config_file(); if (strstr(filename, " ")) { strs = g_strsplit(filename, " ", -1); filename_sh = g_strjoinv("\\ ", strs); g_strfreev(strs); } else filename_sh = g_strdup(filename); comline = g_strdup_printf("%s %s", PACKAGE, filename_sh); DV(g_print(">%s\n", comline)); g_free(filename_sh); g_spawn_command_line_async(comline, NULL); g_free(comline); } g_free(filename); i++; } g_strfreev(files); } else { clear_current_keyval(); undo_set_sequency(FALSE); #if GTK_CHECK_VERSION(2, 10, 0) if (info == TARGET_UTF8_STRING) { #else if (info == TARGET_SELF) { #endif undo_set_sequency_reserve(); context->action = GDK_ACTION_MOVE; } else if (info == TARGET_PLAIN && g_utf8_validate((gchar *)selection_data->data, -1, NULL)) { selection_data->type = gdk_atom_intern("UTF8_STRING", FALSE); } } return; } static gboolean dnd_drag_motion_handler(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GList *targets; gchar *name; gboolean flag = FALSE; targets = context->targets; while (targets) { name = gdk_atom_name(targets->data); DV(g_print("%s\n", name)); if (g_ascii_strcasecmp(name, "text/uri-list") == 0) flag = TRUE; g_free(name); targets = targets->next; } /* if (flag) context->action = GDK_ACTION_DEFAULT; else context->action = GDK_ACTION_COPY; // g_signal_stop_emission_by_name(widget, "drag_motion"); */ /* if (!flag) { gint bx, by; GtkTextIter iter; gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_WIDGET, x, y, &bx, &by); gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, bx, by); if (!dnd_mark) { dnd_mark = gtk_text_buffer_create_mark(GTK_TEXT_VIEW(widget)->buffer, NULL, &iter, TRUE); gtk_text_mark_set_visible(dnd_mark, TRUE); } else gtk_text_mark_set_visible(dnd_mark, FALSE); gtk_text_buffer_move_mark(GTK_TEXT_VIEW(widget)->buffer, dnd_mark, &iter); gtk_text_mark_set_visible(dnd_mark, TRUE); } */ return flag; }