126
126
doc_unre_new_group(doc);
129
#define WS_POS_UNDEFINED G_MAXINT
130
131
split_lines_backend(Tdocument * doc, gint start, gint end)
132
133
gint coffset = 0; /* the offset that we have introduced since the start of this function call */
133
134
gint count = 0, tabsize;
134
gint startws = 0, endws = 0, starti = start, endi = -1, requested_size;
135
gint startws = 0, endws = 0, starti = start, endi = -1, requested_size;
135
136
/* ws= whitespace, i=indenting, these are character positions in the GtkTextBufferr !!!!!!!! */
146
147
DEBUG_MSG("split_lines_backend, from %d:%d on right margin %d\n",start,end, requested_size);
147
148
c = g_utf8_get_char(p);
148
149
while (c != '\0') {
149
if (count > requested_size) {
151
g_print("%d '%c'\n",charpos,c<128?c:'Q');
153
if (count > requested_size && startws!=WS_POS_UNDEFINED) {
150
154
gchar *new_indenting, *tmp1, *tmp2;
151
155
if (startws >= endws)
153
DEBUG_MSG("split_lines, count=%d, startws=%d, endws=%d, coffset=%d c='%c'\n", count, startws,
157
DEBUG_MSG("split_lines, count=%d(>%d), startws=%d, endws=%d, coffset=%d c='%c'\n", count,requested_size, startws,
154
158
endws, coffset, c);
155
159
if (starti == endi || endi==-1) {
156
160
new_indenting = g_strdup("\n");
166
170
DEBUG_MSG("split_lines_backend, replace from startws=%d to endws=%d with offset %d with new indenting\n", startws, endws, coffset);
167
171
count = charpos - endws;
173
tmp1 = doc_get_chars(doc, startws + coffset, endws + coffset);
174
g_print("replace '%s' with newline + identing\n",tmp1);
168
177
doc_replace_text_backend(doc, new_indenting, startws + coffset, endws + coffset);
169
178
coffset += (g_utf8_strlen(new_indenting, -1) - (endws - startws));
170
DEBUG_MSG("split_lines_backend, new coffset=%d, new count=%d\n", coffset, count);
179
DEBUG_MSG("split_lines_backend, new coffset=%d, new count=%d, set startws=%d and endws=%d\n", coffset, count, 0,charpos);
180
startws = WS_POS_UNDEFINED;
181
endws = WS_POS_UNDEFINED;
173
182
g_free(new_indenting);
176
185
count += tabsize;
177
if (startws < endws) {
186
if (startws < endws || startws==WS_POS_UNDEFINED) {
178
187
startws = charpos;
180
189
DEBUG_MSG("split_lines_backend, tab, set startws to %d\n", startws);
182
191
} else if (c == ' ') {
184
if (startws < endws) {
193
if (startws < endws || startws==WS_POS_UNDEFINED) {
185
194
startws = charpos;
187
196
DEBUG_MSG("split_lines_backend, space, set startws to %d\n", startws);
196
205
if (starti > endi) {
198
DEBUG_MSG("split_lines_backend, non-whitespace, set endi to %d, starti=%d\n", endi, starti);
199
} else if (startws >= endws) {
207
DEBUG_MSG("split_lines_backend, non-whitespace (%c) and no valid endi, set endi to %d, starti=%d\n", c<128?c:'Q',endi, starti);
208
} else if (startws >= endws && startws!=WS_POS_UNDEFINED) {
201
DEBUG_MSG("split_lines_backend, non-whitespace, set endws to %d\n", endws);
210
DEBUG_MSG("split_lines_backend, non-whitespace (%c) and no valid endws, set endws to %d\n", c<128?c:'Q', endws);
204
213
p = g_utf8_next_char(p);
435
444
innerblock = !innerblock;
438
447
gtk_text_buffer_get_iter_at_mark(doc->buffer, &cursor, gtk_text_buffer_get_insert(doc->buffer));
439
448
DEBUG_MSG("select_between_matching_block_boundaries, innerblock=%d, location=%d\n", innerblock, gtk_text_iter_get_offset(&cursor));
440
449
offset = gtk_text_iter_get_offset(&cursor);
441
if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view),
450
if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view),
442
451
offset, innerblock, &so, &eo)) {
443
452
DEBUG_MSG("select_between_matching_block_boundaries, no block, return\n");
446
455
if (innerblock && gtk_text_iter_equal(&so, &eo)) {
447
456
DEBUG_MSG("select_between_matching_block_boundaries, iters are equal, request innerblock=FALSE\n");
448
457
innerblock = FALSE;
449
if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view),
458
if (!bluefish_text_view_get_active_block_boundaries(BLUEFISH_TEXT_VIEW(doc->view),
450
459
offset, innerblock, &so, &eo)) {
451
460
DEBUG_MSG("select_between_matching_block_boundaries, innerblock=FALSE, no block, return\n");
455
464
gtk_text_buffer_select_range(doc->buffer, &so, &eo);
488
doc_move_selection(Tdocument *doc, gboolean up)
497
doc_move_selection(Tdocument *doc, gboolean up, gboolean curline_if_no_selection)
490
499
GtkTextIter so, eo;
492
501
gint offset, size;
493
502
if (!gtk_text_buffer_get_selection_bounds(doc->buffer, &so, &eo)) {
503
DEBUG_MSG("doc_move_selection, no selection, select the current line!\n");
504
if (curline_if_no_selection) {
505
gtk_text_buffer_get_iter_at_mark(doc->buffer,&so,gtk_text_buffer_get_insert(doc->buffer));
496
511
/* so and eo are guaranteed to be in ascending order */
512
if (gtk_text_iter_equal(&so, &eo)) {
513
gtk_text_iter_forward_char(&eo);
515
if (!gtk_text_iter_starts_line(&so))
516
gtk_text_iter_set_line_offset(&so, 0);
517
if (!gtk_text_iter_starts_line(&eo))
518
gtk_text_iter_forward_line(&eo);
497
520
doc_unre_new_group(doc);
498
521
doc_block_undo_reg(doc);
500
523
offset = gtk_text_iter_get_offset(&so);
524
DEBUG_MSG("start moving text from %d:%d\n",gtk_text_iter_get_offset(&so),gtk_text_iter_get_offset(&eo));
501
525
size = gtk_text_iter_get_offset(&eo)-offset;
502
526
text = gtk_text_buffer_get_text(doc->buffer,&so,&eo,TRUE);
503
527
/*g_print("doc_move_selection, got selection %d:%d\n",offset,offset+size);*/
504
528
gtk_text_buffer_delete(doc->buffer, &so, &eo);
505
529
doc_unre_add(doc, text, offset, offset+size, UndoDelete);
507
/* now we have to move the cursor up */
531
/* now we have to move the cursor up,
532
because we changed the text we invalidated all iters, so get them again */
508
533
gtk_text_buffer_get_iter_at_offset(doc->buffer, &so, offset);
510
535
gtk_text_iter_backward_line(&so);
536
DEBUG_MSG("UP -> new start location is at %d\n",gtk_text_iter_get_offset(&so));
512
538
gtk_text_iter_forward_line(&so);
539
DEBUG_MSG("DOWN -> new start location is at %d\n",gtk_text_iter_get_offset(&so));
514
541
offset = gtk_text_iter_get_offset(&so);
515
542
gtk_text_buffer_insert(doc->buffer,&so,text,-1);
519
546
doc_unblock_undo_reg(doc);
520
547
doc_set_modified(doc, 1);
521
548
doc_unre_new_group(doc);
523
550
/* and select the text again */
524
/*g_print("doc_move_selection, select %d:%d\n",offset,offset+size);*/
551
DEBUG_MSG("doc_move_selection, select %d:%d\n",offset,offset+size);
525
552
gtk_text_buffer_get_iter_at_offset(doc->buffer, &so, offset);
526
553
gtk_text_buffer_get_iter_at_offset(doc->buffer, &eo, offset+size);
554
DEBUG_MSG("select new location %d:%d\n",gtk_text_iter_get_offset(&so),gtk_text_iter_get_offset(&eo));
527
555
gtk_text_buffer_select_range(doc->buffer,&so,&eo);
537
565
tmp = run_file_select_dialog(GTK_WINDOW(BFWIN(doc->bfwin)->main_window)
538
566
, NULL, relativeto,GTK_FILE_CHOOSER_ACTION_OPEN);
540
doc_insert_two_strings(doc, tmp, NULL);
568
doc_insert_two_strings(doc, tmp, NULL);
541
569
g_free(relativeto);