1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2000 - 2004 Naba Kumar
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
36 #include <libanjuta/resources.h>
37 #include <libanjuta/anjuta-utils.h>
38 #include <libanjuta/anjuta-encodings.h>
39 #include <libanjuta/anjuta-convert.h>
40 #include <libanjuta/anjuta-debug.h>
41 #include <libanjuta/anjuta-shell.h>
42 #include <libanjuta/interfaces/ianjuta-document-manager.h>
43 #include <libanjuta/interfaces/ianjuta-editor.h>
44 #include <libanjuta/interfaces/ianjuta-editor-selection.h>
45 #include <libanjuta/interfaces/ianjuta-editor-convert.h>
46 #include <libanjuta/interfaces/ianjuta-editor-line-mode.h>
47 #include <libanjuta/interfaces/ianjuta-editor-view.h>
48 #include <libanjuta/interfaces/ianjuta-editor-folds.h>
49 #include <libanjuta/interfaces/ianjuta-editor-comment.h>
50 #include <libanjuta/interfaces/ianjuta-editor-zoom.h>
51 #include <libanjuta/interfaces/ianjuta-editor-goto.h>
52 #include <libanjuta/interfaces/ianjuta-editor-language.h>
53 #include <libanjuta/interfaces/ianjuta-editor-tip.h>
54 #include <libanjuta/interfaces/ianjuta-editor-assist.h>
55 #include <libanjuta/interfaces/ianjuta-editor-search.h>
56 #include <libanjuta/interfaces/ianjuta-editor-hover.h>
57 #include <libanjuta/interfaces/ianjuta-editor-factory.h>
58 #include <libanjuta/interfaces/ianjuta-file.h>
59 #include <libanjuta/interfaces/ianjuta-file-savable.h>
60 #include <libanjuta/interfaces/ianjuta-markable.h>
61 #include <libanjuta/interfaces/ianjuta-indicable.h>
62 #include <libanjuta/interfaces/ianjuta-print.h>
63 #include <libanjuta/interfaces/ianjuta-document.h>
64 #include <libanjuta/interfaces/ianjuta-symbol-manager.h>
66 #include "properties.h"
67 #include "text_editor.h"
68 #include "text_editor_cbs.h"
69 #include "text-editor-iterable.h"
75 #include "Scintilla.h"
77 #include "ScintillaWidget.h"
81 #include "text_editor_prefs.h"
83 /* Order is important, as marker with the lowest number is drawn first */
84 #define TEXT_EDITOR_BOOKMARK 0
85 #define TEXT_EDITOR_BREAKPOINT_DISABLED 1
86 #define TEXT_EDITOR_BREAKPOINT_ENABLED 2
87 #define TEXT_EDITOR_PROGRAM_COUNTER 3
88 #define TEXT_EDITOR_LINEMARKER 4
90 #define RATE_LIMIT_IN_MS 2000
92 /* Include marker pixmaps */
93 #include "anjuta-bookmark-16.xpm"
94 #include "anjuta-breakpoint-disabled-16.xpm"
95 #include "anjuta-breakpoint-enabled-16.xpm"
96 #include "anjuta-pcmark-16.xpm"
97 #include "anjuta-linemark-16.xpm"
99 static gchar
** marker_pixmap
[] =
101 anjuta_bookmark_16_xpm
,
102 anjuta_breakpoint_disabled_16_xpm
,
103 anjuta_breakpoint_enabled_16_xpm
,
104 anjuta_pcmark_16_xpm
,
105 anjuta_linemark_16_xpm
,
109 /* Editor language supports */
110 static GList
*supported_languages
= NULL
;
111 static GHashTable
*supported_languages_name
= NULL
;
112 static GHashTable
*supported_languages_ext
= NULL
;
113 static GHashTable
*supported_languages_by_lexer
= NULL
;
115 static void text_editor_finalize (GObject
*obj
);
116 static void text_editor_dispose (GObject
*obj
);
117 static void text_editor_hilite_one (TextEditor
* te
, AnEditorID editor
);
119 static GtkBoxClass
*parent_class
;
123 text_editor_instance_init (TextEditor
*te
)
128 te
->popup_menu
= NULL
;
131 te
->force_hilite
= NULL
;
132 te
->force_pref
= FALSE
;
133 te
->freeze_count
= 0;
134 te
->current_line
= 0;
135 te
->popup_menu
= NULL
;
137 te
->first_time_expose
= TRUE
;
139 te
->notify_ids
= NULL
;
140 te
->hover_tip_on
= FALSE
;
141 te
->last_saved_content
= NULL
;
142 te
->force_not_saved
= FALSE
;
143 te
->message_area
= NULL
;
146 te
->completion_count
= 0;
147 te
->completion_string
= g_string_sized_new (256);
148 te
->completion_finished
= FALSE
;
150 te
->settings
= g_settings_new (PREF_SCHEMA
);
151 te
->docman_settings
= g_settings_new (DOCMAN_PREF_SCHEMA
);
152 te
->msgman_settings
= g_settings_new (MSGMAN_PREF_SCHEMA
);
153 te
->editor_settings
= g_settings_new (ANJUTA_PREF_SCHEMA_PREFIX IANJUTA_EDITOR_PREF_SCHEMA
);
155 gtk_orientable_set_orientation (GTK_ORIENTABLE (te
), GTK_ORIENTATION_VERTICAL
);
159 anjuta_message_area_new (const gchar
*text
,
162 GtkInfoBar
*message_area
;
163 GtkWidget
*content_area
;
164 GtkWidget
*message_label
= gtk_label_new ("");
166 message_area
= GTK_INFO_BAR (gtk_info_bar_new ());
167 gtk_info_bar_set_message_type (message_area
, type
);
168 content_area
= gtk_info_bar_get_content_area (GTK_INFO_BAR (message_area
));
169 gtk_widget_show (message_label
);
170 gtk_container_add (GTK_CONTAINER (content_area
), message_label
);
172 gchar
*markup
= g_strdup_printf ("<b>%s</b>", text
);
173 gtk_label_set_markup (GTK_LABEL (message_label
), markup
);
176 return GTK_WIDGET (message_area
);
180 text_editor_class_init (TextEditorClass
*klass
)
182 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
184 parent_class
= g_type_class_peek_parent (klass
);
185 object_class
->finalize
= text_editor_finalize
;
186 object_class
->dispose
= text_editor_dispose
;
191 check_tm_file(TextEditor
*te
)
193 if (NULL
== te
->tm_file
)
196 // te->tm_file = tm_workspace_find_object(
197 //TM_WORK_OBJECT(app->tm_workspace), te->uri, FALSE);
198 if (NULL
== te
->tm_file
)
200 te
->tm_file
= tm_source_file_new(te
->uri
, TRUE
);
201 if (NULL
!= te
->tm_file
)
202 tm_workspace_add_object(te
->tm_file
);
209 initialize_markers (TextEditor
* te
, GtkWidget
*scintilla
)
213 g_return_if_fail (te
!= NULL
);
216 for (xpm
= marker_pixmap
;*xpm
!= NULL
; xpm
++)
218 scintilla_send_message (SCINTILLA (scintilla
), SCI_MARKERDEFINEPIXMAP
,
219 marker
, (sptr_t
)*xpm
);
224 /* Hack to simulate async loading */
226 emit_opened (TextEditor
* te
)
228 g_signal_emit_by_name (te
, "opened");
235 on_scintila_already_destroyed (gpointer te
, GObject
*obj
)
237 /* DEBUG_PRINT ("%s", "Scintilla object has been destroyed"); */
241 on_te_already_destroyed (gpointer te
, GObject
*obj
)
243 /* DEBUG_PRINT ("%s", "TextEditor object has been destroyed"); */
247 /* Indicators are setup in both TextEditor and AnEditor object.
248 * AnEditor reads the property file while TexEditor uses the
249 * GSettings object. TextEditor can overwrite properties
253 text_editor_setup_indicators_color (TextEditor
*te
)
258 /* Important color */
259 spec
= g_settings_get_string (te
->msgman_settings
, MSGMAN_COLOR_IMPORTANT
);
260 if (gdk_color_parse (spec
, &color
))
262 glong param
= ((color
.red
>> 8) & 0xFF) + (color
.green
& 0xFF00) + ((color
.blue
<< 8) & 0x00FF0000);
263 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_INDICSETFORE
, 0, param
);
267 spec
= g_settings_get_string (te
->msgman_settings
, MSGMAN_COLOR_WARNING
);
268 if (gdk_color_parse (spec
, &color
))
270 glong param
= ((color
.red
>> 8) & 0xFF) + (color
.green
& 0xFF00) + ((color
.blue
<< 8) & 0x00FF0000);
271 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_INDICSETFORE
, 1, param
);
275 spec
= g_settings_get_string (te
->msgman_settings
, MSGMAN_COLOR_ERROR
);
276 if (gdk_color_parse (spec
, &color
))
278 glong param
= ((color
.red
>> 8) & 0xFF) + (color
.green
& 0xFF00) + ((color
.blue
<< 8) & 0x00FF0000);
279 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_INDICSETFORE
, 2, param
);
285 text_editor_setup_indentation_settings (TextEditor
*te
)
287 AnEditorID editor_id
;
288 GtkWidget
*scintilla
;
291 editor_id
= aneditor_new (sci_prop_get_pointer (te
->props_base
));
292 scintilla
= aneditor_get_widget (editor_id
);
294 value
= g_settings_get_boolean (te
->settings
, TAB_INDENTS
);
295 scintilla_send_message (SCINTILLA (scintilla
), SCI_SETTABINDENTS
, value
? 1 : 0, 0);
296 value
= g_settings_get_boolean (te
->settings
, BACKSPACE_UNINDENTS
);
297 scintilla_send_message (SCINTILLA (scintilla
), SCI_SETBACKSPACEUNINDENTS
, value
? 1 : 0, 0);
301 text_editor_add_view (TextEditor
*te
)
303 AnEditorID editor_id
;
304 GtkWidget
*scintilla
;
310 current_line
= text_editor_get_current_lineno (te
);
311 current_point
= text_editor_get_current_position (te
);
318 editor_id
= aneditor_new (sci_prop_get_pointer (te
->props_base
));
319 scintilla
= aneditor_get_widget (editor_id
);
321 /* Set notifications to receive */
322 scintilla_send_message (SCINTILLA (scintilla
), SCI_SETMODEVENTMASK
,
323 (SC_MOD_INSERTTEXT
| SC_MOD_DELETETEXT
), 0);
325 /* Set parent, if it is not primary view */
328 aneditor_set_parent (editor_id
, GPOINTER_TO_INT(te
->editor_id
));
330 te
->views
= g_list_prepend (te
->views
, GINT_TO_POINTER (editor_id
));
331 te
->editor_id
= editor_id
;
332 te
->scintilla
= scintilla
;
335 aneditor_command (te->editor_id, ANE_SETACCELGROUP,
336 (glong) app->accel_group, 0);
339 gtk_widget_set_size_request (scintilla
, 50, 50);
340 gtk_widget_show (scintilla
);
342 gtk_box_set_spacing (GTK_BOX (te
->vbox
), 3);
343 gtk_box_pack_start (GTK_BOX (te
->vbox
), scintilla
, TRUE
, TRUE
, 0);
344 gtk_widget_grab_focus (scintilla
);
346 g_signal_connect (G_OBJECT (scintilla
), "event",
347 G_CALLBACK (on_text_editor_text_event
), te
);
348 g_signal_connect (G_OBJECT (scintilla
), "button_press_event",
349 G_CALLBACK (on_text_editor_text_buttonpress_event
), te
);
350 g_signal_connect (G_OBJECT (scintilla
), "key_release_event",
351 G_CALLBACK (on_text_editor_text_keyrelease_event
), te
);
352 g_signal_connect_after (G_OBJECT (scintilla
), "size_allocate",
353 G_CALLBACK (on_text_editor_scintilla_size_allocate
), te
);
354 g_signal_connect (G_OBJECT (scintilla
), "sci-notify",
355 G_CALLBACK (on_text_editor_scintilla_notify
), te
);
356 g_signal_connect (G_OBJECT (scintilla
), "focus_in_event",
357 G_CALLBACK (on_text_editor_scintilla_focus_in
), te
);
359 initialize_markers (te
, scintilla
);
360 text_editor_hilite_one (te
, editor_id
);
361 text_editor_set_line_number_width (te
);
364 text_editor_goto_line (te
, current_line
, FALSE
, TRUE
);
366 text_editor_goto_point (te
, current_point
);
369 g_object_weak_ref (G_OBJECT (scintilla
), on_scintila_already_destroyed
, te
);
373 /* Remove the current view */
375 text_editor_remove_view (TextEditor
*te
)
379 if (te
->views
== NULL
||
380 g_list_length (te
->views
) <= 1)
383 g_signal_handlers_disconnect_by_func (G_OBJECT (te
->scintilla
),
384 G_CALLBACK (on_text_editor_text_event
), te
);
385 g_signal_handlers_disconnect_by_func (G_OBJECT (te
->scintilla
),
386 G_CALLBACK (on_text_editor_text_buttonpress_event
), te
);
387 g_signal_handlers_disconnect_by_func (G_OBJECT (te
->scintilla
),
388 G_CALLBACK (on_text_editor_text_keyrelease_event
), te
);
389 g_signal_handlers_disconnect_by_func (G_OBJECT (te
->scintilla
),
390 G_CALLBACK (on_text_editor_scintilla_size_allocate
), te
);
391 g_signal_handlers_disconnect_by_func (G_OBJECT (te
->scintilla
),
392 G_CALLBACK (on_text_editor_scintilla_notify
), te
);
393 g_signal_handlers_disconnect_by_func (G_OBJECT (te
->scintilla
),
394 G_CALLBACK (on_text_editor_scintilla_focus_in
), te
);
396 te
->views
= g_list_remove (te
->views
, GINT_TO_POINTER(te
->editor_id
));
397 gtk_container_remove (GTK_CONTAINER (te
->vbox
), te
->scintilla
);
398 aneditor_destroy(te
->editor_id
);
400 /* Set current view */
403 te
->editor_id
= GPOINTER_TO_INT(te
->views
->data
);
404 te
->scintilla
= aneditor_get_widget (te
->editor_id
);
405 gtk_widget_grab_focus (te
->scintilla
);
409 gtk_box_set_spacing (GTK_BOX (te
->vbox
), 0);
411 te
->scintilla
= NULL
;
416 on_reload_dialog_response (GtkWidget
*message_area
, gint res
, TextEditor
*te
)
418 if (res
== GTK_RESPONSE_YES
)
420 gint visible_line
= scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GETFIRSTVISIBLELINE
, 0, 0);
421 text_editor_load_file (te
);
422 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_SETFIRSTVISIBLELINE
, visible_line
, 0);
426 text_editor_set_saved (te
, FALSE
);
427 gtk_widget_destroy (message_area
);
432 on_destroy_message_area (gpointer data
, GObject
*finalized_object
)
434 TextEditor
*te
= (TextEditor
*)data
;
436 te
->message_area
= NULL
;
437 g_signal_emit_by_name (G_OBJECT (te
), "update-save-ui");
441 on_close_dialog_response (GtkWidget
*message_area
, gint res
, TextEditor
*te
)
443 if (res
== GTK_RESPONSE_YES
)
445 IAnjutaDocumentManager
*docman
;
447 docman
= anjuta_shell_get_interface (te
->shell
, IAnjutaDocumentManager
, NULL
);
448 if (docman
== NULL
) return;
450 ianjuta_document_manager_remove_document (docman
, IANJUTA_DOCUMENT (te
), FALSE
, NULL
);
454 text_editor_set_saved (te
, FALSE
);
455 gtk_widget_destroy (message_area
);
460 text_editor_set_message_area (TextEditor
*te
, GtkWidget
*message_area
)
462 if (te
->message_area
!= NULL
)
463 gtk_widget_destroy (te
->message_area
);
464 te
->message_area
= message_area
;
466 if (te
->message_area
== NULL
)
469 gtk_widget_show (message_area
);
470 gtk_box_pack_start (GTK_BOX (te
),
475 g_object_weak_ref (G_OBJECT (te
->message_area
),
476 on_destroy_message_area
, te
);
478 g_signal_emit_by_name (G_OBJECT (te
), "update-save-ui");
482 on_text_editor_uri_changed (GFileMonitor
*monitor
,
485 GFileMonitorEvent event_type
,
488 TextEditor
*te
= TEXT_EDITOR (user_data
);
489 GtkWidget
*message_area
;
492 /* DEBUG_PRINT ("%s", "File changed!!!"); */
496 case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT
:
498 if (!anjuta_util_diff (te
->uri
, te
->last_saved_content
))
500 /* The file content is same. Remove any previous prompt for reload */
501 if (te
->message_area
)
502 gtk_widget_destroy (te
->message_area
);
503 te
->message_area
= NULL
;
508 case G_FILE_MONITOR_EVENT_CREATED
:
509 if (text_editor_is_saved (te
))
511 buff
= g_strdup_printf (_("The file '%s' has been changed.\n"
512 "Do you want to reload it?"),
517 buff
= g_strdup_printf (_("The file '%s' has been changed.\n"
518 "Do you want to lose your changes and reload it?"),
521 message_area
= anjuta_message_area_new (buff
, GTK_MESSAGE_WARNING
);
523 gtk_info_bar_add_button (GTK_INFO_BAR (message_area
),
526 gtk_info_bar_add_button (GTK_INFO_BAR (message_area
),
529 g_signal_connect (G_OBJECT(message_area
), "response",
530 G_CALLBACK (on_reload_dialog_response
),
533 case G_FILE_MONITOR_EVENT_DELETED
:
534 if (text_editor_is_saved (te
))
536 buff
= g_strdup_printf (_
537 ("The file '%s' has been deleted.\n"
538 "Do you confirm and close it?"),
543 buff
= g_strdup_printf (_
544 ("The file '%s' has been deleted.\n"
545 "Do you want to lose your changes and close it?"),
548 message_area
= anjuta_message_area_new (buff
, GTK_MESSAGE_WARNING
);
550 gtk_info_bar_add_button (GTK_INFO_BAR (message_area
),
553 gtk_info_bar_add_button (GTK_INFO_BAR (message_area
),
556 g_signal_connect (G_OBJECT(message_area
), "response",
557 G_CALLBACK (on_close_dialog_response
),
560 case G_FILE_MONITOR_EVENT_CHANGED
:
561 case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED
:
562 case G_FILE_MONITOR_EVENT_PRE_UNMOUNT
:
563 case G_FILE_MONITOR_EVENT_UNMOUNTED
:
566 g_warn_if_reached ();
570 text_editor_set_message_area (te
, message_area
);
574 text_editor_update_monitor (TextEditor
*te
, gboolean disable_it
)
578 /* Shutdown existing monitor */
579 g_file_monitor_cancel (te
->monitor
);
582 if (te
->message_area
)
584 /* Remove existing message area */
585 gtk_widget_destroy (te
->message_area
);
586 te
->message_area
= NULL
;
588 if (te
->uri
&& !disable_it
)
591 GError
*error
= NULL
;
592 /* DEBUG_PRINT ("%s", "Setting up Monitor for %s", te->uri); */
594 gio_uri
= g_file_new_for_uri (te
->uri
);
595 te
->monitor
= g_file_monitor_file (gio_uri
,
599 g_file_monitor_set_rate_limit (te
->monitor
, RATE_LIMIT_IN_MS
);
600 g_signal_connect (te
->monitor
, "changed",
601 G_CALLBACK (on_text_editor_uri_changed
), te
);
602 g_object_unref (gio_uri
);
606 DEBUG_PRINT ("Error while setting up file monitor: %s",
608 g_error_free (error
);
615 on_shell_value_changed (TextEditor
*te
, const char *name
)
617 g_return_if_fail (name
!= NULL
);
619 if ((strcmp (name
, TEXT_EDITOR_PROJECT_TYPE_LIST
) == 0) ||
620 (strcmp (name
, TEXT_EDITOR_SYSTEM_TYPE_LIST
) == 0))
622 /* Type names list has changed, so refresh highlight */
623 text_editor_hilite (te
, te
->force_pref
);
628 on_style_changed (TextEditor
*te
)
630 /* Refresh highlight */
631 text_editor_hilite (te
, te
->force_pref
);
635 on_indicators_changed (TextEditor
*te
)
637 /* Refresh indicator */
638 text_editor_setup_indicators_color (te
);
642 text_editor_new (AnjutaPlugin
*plugin
, const gchar
*uri
, const gchar
*name
)
644 AnjutaShell
*shell
= plugin
->shell
;
645 AnjutaStatus
*status
= anjuta_shell_get_status (shell
, NULL
);
646 TextEditor
*te
= TEXT_EDITOR (gtk_widget_new (TYPE_TEXT_EDITOR
, NULL
));
648 static guint new_file_count
;
653 te
->props_base
= text_editor_get_props();
654 if (name
&& strlen(name
) > 0)
655 te
->filename
= g_strdup(name
);
657 te
->filename
= g_strdup_printf ("Newfile#%d", ++new_file_count
);
658 if (uri
&& strlen(uri
) > 0)
661 g_free (te
->filename
);
665 gio_uri
= g_file_new_for_uri (uri
);
666 te
->filename
= g_file_get_basename (gio_uri
);
667 g_object_unref (gio_uri
);
669 te
->uri
= g_strdup (uri
);
672 /* Create primary view */
673 te
->vbox
= gtk_box_new (GTK_ORIENTATION_VERTICAL
, 3);
674 gtk_box_pack_end (GTK_BOX (te
), te
->vbox
, TRUE
, TRUE
, 0);
675 text_editor_add_view (te
);
677 text_editor_prefs_init (te
);
681 if (text_editor_load_file (te
) == FALSE
)
683 /* Unable to load file */
684 gtk_widget_destroy (GTK_WIDGET (te
));
688 text_editor_update_controls (te
);
690 /* Apply font zoom separately */
691 zoom_factor
= g_settings_get_int (te
->docman_settings
, TEXT_ZOOM_FACTOR
);
692 /* DEBUG_PRINT ("%s", "Initializing zoom factor to: %d", zoom_factor); */
693 text_editor_set_zoom_factor (te
, zoom_factor
);
694 text_editor_setup_indicators_color (te
);
695 text_editor_setup_indentation_settings (te
);
697 /* Get type name notification */
698 g_signal_connect_swapped (G_OBJECT (shell
), "value-added", G_CALLBACK (on_shell_value_changed
), te
);
699 g_signal_connect_swapped (G_OBJECT (shell
), "value-removed", G_CALLBACK (on_shell_value_changed
), te
);
700 g_signal_connect_swapped (G_OBJECT (plugin
), "style-changed", G_CALLBACK(on_style_changed
), te
);
701 g_signal_connect_swapped (G_OBJECT (te
), "style-updated", G_CALLBACK(on_style_changed
), te
);
703 g_signal_connect_swapped (G_OBJECT(te
->msgman_settings
), "changed", G_CALLBACK (on_indicators_changed
), te
);
706 g_object_weak_ref (G_OBJECT (te
), on_te_already_destroyed
, te
);
708 return GTK_WIDGET (te
);
712 text_editor_dispose (GObject
*obj
)
714 TextEditor
*te
= TEXT_EDITOR (obj
);
716 /* Disconnect signal */
717 g_signal_handlers_disconnect_by_func (te
->shell
, G_CALLBACK (on_shell_value_changed
), te
);
721 text_editor_update_monitor (te
, TRUE
);
726 g_object_unref (te
->popup_menu
);
727 te
->popup_menu
= NULL
;
731 GtkWidget
*scintilla
;
732 AnEditorID editor_id
;
738 editor_id
= GPOINTER_TO_INT (node
->data
);
739 scintilla
= aneditor_get_widget (editor_id
);
741 g_signal_handlers_disconnect_by_func (G_OBJECT (scintilla
),
742 G_CALLBACK (on_text_editor_text_event
), te
);
743 g_signal_handlers_disconnect_by_func (G_OBJECT (scintilla
),
744 G_CALLBACK (on_text_editor_text_buttonpress_event
), te
);
745 g_signal_handlers_disconnect_by_func (G_OBJECT (scintilla
),
746 G_CALLBACK (on_text_editor_text_keyrelease_event
), te
);
747 g_signal_handlers_disconnect_by_func (G_OBJECT (scintilla
),
748 G_CALLBACK (on_text_editor_scintilla_size_allocate
), te
);
749 g_signal_handlers_disconnect_by_func (G_OBJECT (scintilla
),
750 G_CALLBACK (on_text_editor_scintilla_notify
), te
);
751 g_signal_handlers_disconnect_by_func (G_OBJECT (scintilla
),
752 G_CALLBACK (on_text_editor_scintilla_focus_in
), te
);
754 aneditor_destroy (editor_id
);
755 node
= g_list_next (node
);
757 te
->scintilla
= NULL
;
763 text_editor_prefs_finalize (te
);
764 te
->notify_ids
= NULL
;
768 g_list_free (te
->provider
);
771 if (te
->completion_string
)
773 g_string_free (te
->completion_string
, TRUE
);
774 te
->completion_string
= NULL
;
776 te
->completion_count
= 0;
777 g_object_unref (te
->settings
);
778 g_object_unref (te
->docman_settings
);
779 g_object_unref (te
->msgman_settings
);
780 g_object_unref (te
->editor_settings
);
781 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
785 text_editor_finalize (GObject
*obj
)
787 TextEditor
*te
= TEXT_EDITOR (obj
);
788 g_free (te
->filename
);
790 g_free (te
->force_hilite
);
791 g_free (te
->last_saved_content
);
793 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
797 text_editor_freeze (TextEditor
*te
)
803 text_editor_thaw (TextEditor
*te
)
806 if (te
->freeze_count
< 0)
807 te
->freeze_count
= 0;
811 text_editor_set_hilite_type (TextEditor
* te
, const gchar
*file_extension
)
813 const gchar
*past_language
;
814 const gchar
*curr_language
;
816 past_language
= ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (te
), NULL
);
818 g_free (te
->force_hilite
);
820 te
->force_hilite
= g_strdup (file_extension
);
822 te
->force_hilite
= NULL
;
824 curr_language
= ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (te
), NULL
);
825 if (past_language
!= curr_language
)
826 g_signal_emit_by_name (te
, "language-changed", curr_language
);
830 text_editor_hilite_one (TextEditor
* te
, AnEditorID editor_id
)
832 const gchar
*name
= NULL
;
833 gchar
*basename
= NULL
;
835 /* syntax highlighting is disabled if te->force_pref && pref is disabled */
836 if (!te
->force_pref
||
837 !g_settings_get_boolean (te
->settings
,
838 DISABLE_SYNTAX_HILIGHTING
))
840 if (te
->force_hilite
)
842 name
= te
->force_hilite
;
846 basename
= g_path_get_basename (te
->uri
);
849 else if (te
->filename
)
857 /* No syntax higlight */
858 aneditor_command (editor_id
, ANE_SETHILITE
, (glong
) "plain.txt", (glong
) 0);
862 const gchar
*typedef_hl
[2];
863 GValue sys_value
= {0,};
864 GValue prj_value
= {0,};
866 anjuta_shell_get_value (te
->shell
, TEXT_EDITOR_SYSTEM_TYPE_LIST
, &sys_value
, NULL
);
867 typedef_hl
[0] = G_VALUE_HOLDS_STRING(&sys_value
) ? g_value_get_string (&sys_value
) : NULL
;
869 anjuta_shell_get_value (te
->shell
, TEXT_EDITOR_PROJECT_TYPE_LIST
, &prj_value
, NULL
);
870 typedef_hl
[1] = G_VALUE_HOLDS_STRING(&prj_value
) ? g_value_get_string (&prj_value
) : NULL
;
872 aneditor_command (editor_id
, ANE_SETHILITE
, (glong
) name
, (glong
) typedef_hl
);
873 if (G_IS_VALUE (&sys_value
)) g_value_unset (&sys_value
);
874 if (G_IS_VALUE (&prj_value
)) g_value_unset (&prj_value
);
880 text_editor_hilite (TextEditor
* te
, gboolean override_by_pref
)
884 te
->force_pref
= override_by_pref
;
888 text_editor_hilite_one (te
, GPOINTER_TO_INT (node
->data
));
889 node
= g_list_next (node
);
892 text_editor_setup_indicators_color (te
);
896 text_editor_set_zoom_factor (TextEditor
* te
, gint zfac
)
898 text_editor_command (te
, ANE_SETZOOM
, zfac
, 0);
902 text_editor_get_attribute (TextEditor
*te
, gint position
)
906 TextEditorAttrib attrib
= TEXT_EDITOR_ATTRIB_TEXT
;
908 lexer
= scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GETLEXER
,
910 style
= scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GETSTYLEAT
,
917 case SCE_C_CHARACTER
:
919 attrib
= TEXT_EDITOR_ATTRIB_STRING
;
922 case SCE_C_COMMENTLINE
:
923 case SCE_C_COMMENTDOC
:
924 case SCE_C_COMMENTLINEDOC
:
925 case SCE_C_COMMENTDOCKEYWORD
:
926 case SCE_C_COMMENTDOCKEYWORDERROR
:
927 attrib
= TEXT_EDITOR_ATTRIB_COMMENT
;
930 attrib
= TEXT_EDITOR_ATTRIB_KEYWORD
;
937 case SCE_P_CHARACTER
:
940 case SCE_P_TRIPLEDOUBLE
:
941 attrib
= TEXT_EDITOR_ATTRIB_STRING
;
943 case SCE_P_COMMENTLINE
:
944 case SCE_P_COMMENTBLOCK
:
945 attrib
= TEXT_EDITOR_ATTRIB_COMMENT
;
949 attrib
= TEXT_EDITOR_ATTRIB_KEYWORD
;
958 text_editor_find (TextEditor
* te
, const gchar
* str
, gint scope
,
959 gboolean forward
, gboolean regexp
,
960 gboolean ignore_case
, gboolean whole_word
, gboolean wrap
)
965 int current_pos
, current_anchor
;
968 editor
= te
->scintilla
;
970 flags
= (ignore_case
? 0 : SCFIND_MATCHCASE
)
971 | (regexp
? SCFIND_REGEXP
: 0)
972 | (whole_word
? SCFIND_WHOLEWORD
: 0)
973 | (forward
? 0 : ANEFIND_REVERSE_FLAG
);
977 case TEXT_EDITOR_FIND_SCOPE_WHOLE
:
980 scintilla_send_message (SCINTILLA (editor
), SCI_SETANCHOR
,
982 scintilla_send_message (SCINTILLA (editor
),
983 SCI_SETCURRENTPOS
, 0, 0);
988 length
= scintilla_send_message (SCINTILLA (editor
),
989 SCI_GETTEXTLENGTH
, 0, 0);
990 scintilla_send_message (SCINTILLA (editor
),
991 SCI_SETCURRENTPOS
, length
-1, 0);
992 scintilla_send_message (SCINTILLA (editor
),
993 SCI_SETANCHOR
, length
-1, 0);
999 current_pos
= scintilla_send_message (SCINTILLA (editor
),
1000 SCI_GETCURRENTPOS
, 0, 0);
1001 current_anchor
= scintilla_send_message (SCINTILLA (editor
),
1002 SCI_GETANCHOR
, 0, 0);
1003 ret
= aneditor_command (te
->editor_id
, ANE_FIND
, flags
, (long)str
);
1004 if (scope
== TEXT_EDITOR_FIND_SCOPE_CURRENT
&& wrap
&& ret
< 0) {
1005 /* If wrap is requested, wrap it. */
1008 scintilla_send_message (SCINTILLA (editor
), SCI_SETANCHOR
, 0, 0);
1009 scintilla_send_message (SCINTILLA (editor
), SCI_SETCURRENTPOS
,
1015 length
= scintilla_send_message (SCINTILLA (editor
),
1016 SCI_GETTEXTLENGTH
, 0, 0);
1017 scintilla_send_message (SCINTILLA (editor
), SCI_SETCURRENTPOS
,
1019 scintilla_send_message (SCINTILLA (editor
), SCI_SETANCHOR
,
1022 ret
= aneditor_command (te
->editor_id
, ANE_FIND
, flags
, (long)str
);
1023 /* If the text is still not found, restore current pos and anchor */
1025 scintilla_send_message (SCINTILLA (editor
), SCI_SETANCHOR
,
1027 scintilla_send_message (SCINTILLA (editor
), SCI_SETCURRENTPOS
,
1035 text_editor_replace_selection (TextEditor
* te
, const gchar
* r_str
)
1038 scintilla_send_message (SCINTILLA(te
->scintilla
), SCI_REPLACESEL
, 0,
1043 text_editor_get_total_lines (TextEditor
* te
)
1049 if (IS_SCINTILLA (te
->scintilla
) == FALSE
)
1052 i
< scintilla_send_message (SCINTILLA (te
->scintilla
),
1053 SCI_GETLENGTH
, 0, 0); i
++)
1055 if (scintilla_send_message
1056 (SCINTILLA (te
->scintilla
), SCI_GETCHARAT
, i
,
1064 text_editor_get_current_lineno (TextEditor
* te
)
1068 g_return_val_if_fail (te
!= NULL
, 0);
1070 count
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1071 SCI_GETCURRENTPOS
, 0, 0);
1072 count
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1073 SCI_LINEFROMPOSITION
, count
, 0);
1074 return linenum_scintilla_to_text_editor(count
);
1078 text_editor_get_position_lineno (TextEditor
* te
, gint position
)
1081 g_return_val_if_fail (te
!= NULL
, 0);
1083 count
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1084 SCI_LINEFROMPOSITION
, position
, 0);
1085 return linenum_scintilla_to_text_editor(count
);
1089 text_editor_get_current_column (TextEditor
* te
)
1091 g_return_val_if_fail (te
!= NULL
, 0);
1092 return scintilla_send_message (SCINTILLA (te
->scintilla
),
1094 text_editor_get_current_position (te
), 0);
1098 text_editor_get_overwrite (TextEditor
* te
)
1100 g_return_val_if_fail (te
!= NULL
, 0);
1101 return scintilla_send_message (SCINTILLA (te
->scintilla
),
1102 SCI_GETOVERTYPE
, 0, 0);
1106 text_editor_get_line_from_position (TextEditor
* te
, glong pos
)
1110 g_return_val_if_fail (te
!= NULL
, 0);
1112 count
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1113 SCI_LINEFROMPOSITION
, pos
, 0);
1114 return linenum_scintilla_to_text_editor(count
);
1118 text_editor_get_current_position (TextEditor
* te
)
1122 g_return_val_if_fail (te
!= NULL
, 0);
1124 count
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1125 SCI_GETCURRENTPOS
, 0, 0);
1130 text_editor_goto_point (TextEditor
* te
, glong point
)
1132 g_return_val_if_fail (te
!= NULL
, FALSE
);
1133 g_return_val_if_fail(IS_SCINTILLA (te
->scintilla
) == TRUE
, FALSE
);
1135 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GOTOPOS
, point
, 0);
1140 text_editor_goto_line (TextEditor
* te
, glong line
,
1141 gboolean mark
, gboolean ensure_visible
)
1144 g_return_val_if_fail (te
!= NULL
, FALSE
);
1145 g_return_val_if_fail(IS_SCINTILLA (te
->scintilla
) == TRUE
, FALSE
);
1146 g_return_val_if_fail(line
>= 0, FALSE
);
1148 te
->current_line
= line
;
1149 if (mark
) text_editor_set_line_marker (te
, line
);
1151 scintilla_send_message (SCINTILLA (te
->scintilla
),
1153 linenum_text_editor_to_scintilla (line
), 0);
1154 selpos
= scintilla_send_message(SCINTILLA (te
->scintilla
),
1155 SCI_POSITIONFROMLINE
,
1156 linenum_text_editor_to_scintilla (line
), 0);
1157 scintilla_send_message (SCINTILLA (te
->scintilla
),
1158 SCI_SETSELECTIONSTART
, selpos
, 0);
1159 scintilla_send_message (SCINTILLA (te
->scintilla
),
1160 SCI_SETSELECTIONEND
, selpos
, 0);
1162 /* This ensures that we have arround 5 lines visible below the mark */
1163 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GOTOLINE
,
1164 linenum_text_editor_to_scintilla (line
)+5, 0);
1165 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GOTOLINE
,
1166 linenum_text_editor_to_scintilla (line
), 0);
1171 text_editor_goto_block_start (TextEditor
* te
)
1174 line
= aneditor_command (te
->editor_id
, ANE_GETBLOCKSTARTLINE
, 0, 0);
1175 if (line
>= 0) text_editor_goto_line (te
, line
, TRUE
, TRUE
);
1181 text_editor_goto_block_end (TextEditor
* te
)
1184 line
= aneditor_command (te
->editor_id
, ANE_GETBLOCKENDLINE
, 0, 0);
1185 if (line
>= 0) text_editor_goto_line (te
, line
, TRUE
, TRUE
);
1191 text_editor_set_marker (TextEditor
*te
, glong line
, gint marker
)
1193 g_return_val_if_fail (te
!= NULL
, -1);
1194 g_return_val_if_fail(IS_SCINTILLA (te
->scintilla
) == TRUE
, -1);
1196 /* Scintilla interprets line+1 rather than line */
1198 /* So counterbalance it with line-1 */
1199 /* Using the macros linenum_* */
1200 return scintilla_send_message (SCINTILLA (te
->scintilla
),
1202 linenum_text_editor_to_scintilla (line
),
1207 text_editor_set_indicator (TextEditor
*te
, gint start
,
1208 gint end
, gint indicator
)
1210 g_return_val_if_fail (te
!= NULL
, -1);
1211 g_return_val_if_fail (IS_SCINTILLA (te
->scintilla
) == TRUE
, -1);
1213 scintilla_send_message (SCINTILLA (te
->scintilla
),
1214 SCI_SETINDICATORCURRENT
, indicator
, 0);
1215 scintilla_send_message (SCINTILLA (te
->scintilla
),
1216 SCI_INDICATORFILLRANGE
, start
, end
- start
);
1222 text_editor_clear_indicator (TextEditor
*te
, gint start
,
1227 g_return_val_if_fail (te
!= NULL
, -1);
1228 g_return_val_if_fail (IS_SCINTILLA (te
->scintilla
) == TRUE
, -1);
1230 for (i
= 0; i
< 3; i
++)
1232 scintilla_send_message (SCINTILLA (te
->scintilla
),
1233 SCI_SETINDICATORCURRENT
, i
, 0);
1234 scintilla_send_message (SCINTILLA (te
->scintilla
),
1235 SCI_INDICATORCLEARRANGE
, start
, end
- start
);
1242 text_editor_clear_all_indicator (TextEditor
*te
)
1247 g_return_val_if_fail (te
!= NULL
, -1);
1248 g_return_val_if_fail (IS_SCINTILLA (te
->scintilla
) == TRUE
, -1);
1250 last
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1251 SCI_GETTEXTLENGTH
, 0, 0);
1252 for (i
= 0; i
< 3; i
++)
1254 scintilla_send_message (SCINTILLA (te
->scintilla
),
1255 SCI_SETINDICATORCURRENT
, i
, 0);
1256 scintilla_send_message (SCINTILLA (te
->scintilla
),
1257 SCI_INDICATORCLEARRANGE
, 0, last
);
1264 text_editor_set_line_marker (TextEditor
*te
, glong line
)
1266 g_return_if_fail (te
!= NULL
);
1267 g_return_if_fail(IS_SCINTILLA (te
->scintilla
) == TRUE
);
1269 // FIXME: anjuta_delete_all_marker (TEXT_EDITOR_LINEMARKER);
1270 text_editor_delete_marker_all (te
, TEXT_EDITOR_LINEMARKER
);
1271 text_editor_set_marker (te
, line
, TEXT_EDITOR_LINEMARKER
);
1274 /* Support for DOS-Files
1276 * On load, Anjuta will detect DOS-files by finding <CR><LF>.
1277 * Anjuta will translate some chars >= 128 to native charset.
1278 * On save the DOS_EOL_CHECK(preferences->editor) will be checked
1279 * and chars >=128 will be replaced by DOS-codes, if any translation
1280 * match(see struct tr_dos in this file) and <CR><LF> will used
1282 * The DOS_EOL_CHECK-checkbox will be set on loading a DOS-file.
1284 * 23.Sep.2001 Denis Boehme <boehme at syncio dot de>
1288 * this is a translation table from unix->dos
1289 * this table will be used by filter_chars and save filtered.
1292 unsigned char c
; /* unix-char */
1293 unsigned char b
; /* dos-char */
1323 * filter chars in buffer, by using tr_dos-table.
1327 filter_chars_in_dos_mode(gchar
*data_
, size_t size
)
1331 unsigned char * data
= (unsigned char*)data_
;
1332 unsigned char * tr_map
;
1334 tr_map
= (unsigned char *)malloc( 256 );
1335 memset( tr_map
, 0, 256 );
1336 for ( k
= 0; k
< sizeof(tr_dos
)/2 ; k
++ )
1337 tr_map
[tr_dos
[k
].b
] = tr_dos
[k
].c
;
1339 for ( i
= 0; i
< size
; i
++ )
1341 if ( (data
[i
] >= 128) && ( tr_map
[data
[i
]] != 0) )
1342 data
[i
] = tr_map
[data
[i
]];;
1352 * save buffer. filter chars and set dos-like CR/LF if dos_text is set.
1355 save_filtered_in_dos_mode(GFileOutputStream
* stream
, gchar
*data_
,
1360 unsigned char *data
;
1361 unsigned char *tr_map
;
1364 /* build the translation table */
1365 tr_map
= malloc( 256 );
1366 memset( tr_map
, 0, 256 );
1368 for ( k
= 0; k
< sizeof(tr_dos
)/2; k
++)
1369 tr_map
[tr_dos
[k
].c
] = tr_dos
[k
].b
;
1371 data
= (unsigned char*)data_
;
1378 /* convert dos-text */
1379 if ( tr_map
[data
[i
]] != 0 )
1381 gsize bytes_written
;
1382 result
= g_output_stream_write_all (G_OUTPUT_STREAM (stream
),
1383 &tr_map
[data
[i
]], 1,
1391 /* char not found, skip transform */
1392 gsize bytes_written
;
1393 result
= g_output_stream_write_all (G_OUTPUT_STREAM (stream
),
1403 gsize bytes_written
;
1404 result
= g_output_stream_write_all (G_OUTPUT_STREAM (stream
),
1421 determine_editor_mode(gchar
* buffer
, glong size
)
1424 guint cr
, lf
, crlf
, max_mode
;
1429 for ( i
= 0; i
< size
; i
++ )
1431 if ( buffer
[i
] == 0x0a ){
1433 // mode = SC_EOF_LF;
1435 } else if ( buffer
[i
] == 0x0d ) {
1436 if (i
>= (size
-1)) {
1439 // mode = SC_EOL_CR;
1442 if (buffer
[i
+1] != 0x0a) {
1444 // mode = SC_EOL_CR;
1448 // mode = SC_EOL_CRLF;
1456 /* Vote for the maximum */
1459 if (crlf
> max_mode
) {
1463 if (cr
> max_mode
) {
1467 /* DEBUG_PRINT ("EOL chars: LR = %d, CR = %d, CRLF = %d", lf, cr, crlf); */
1468 /* DEBUG_PRINT ("Autodetected Editor mode [%d]", mode); */
1473 convert_to_utf8 (PropsID props
, const gchar
*content
, gsize len
,
1474 const AnjutaEncoding
**encoding_used
)
1476 GError
* conv_error
= NULL
;
1480 new_content
= anjuta_convert_to_utf8 (content
,
1485 if (new_content
== NULL
)
1487 /* Last change, let's try 8859-15 */
1489 anjuta_encoding_get_from_charset("ISO-8859-15");
1491 new_content
= anjuta_convert_to_utf8 (content
,
1499 g_error_free (conv_error
);
1505 load_from_file (TextEditor
*te
, gchar
*uri
, gchar
**err
)
1508 GFileInputStream
*stream
;
1512 gint dos_filter
, editor_mode
;
1513 gchar
*file_content
= NULL
;
1514 gchar
*buffer
= NULL
;
1517 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_CLEARALL
,
1519 gio_uri
= g_file_new_for_uri (uri
);
1520 info
= g_file_query_info (gio_uri
,
1521 G_FILE_ATTRIBUTE_STANDARD_SIZE
,
1522 G_FILE_QUERY_INFO_NONE
,
1528 *err
= g_strdup (_("Could not get file info"));
1529 g_object_unref (gio_uri
);
1533 size
= g_file_info_get_attribute_uint64 (info
, G_FILE_ATTRIBUTE_STANDARD_SIZE
);
1534 g_object_unref (info
);
1536 buffer
= g_malloc (size
+ 1);
1537 if (buffer
== NULL
&& size
!= 0)
1539 /* DEBUG_PRINT ("%s", "This file is too big. Unable to allocate memory."); */
1540 *err
= g_strdup (_("This file is too big. Unable to allocate memory."));
1541 g_object_unref (gio_uri
);
1546 stream
= g_file_read (gio_uri
, NULL
, NULL
);
1549 *err
= g_strdup (_("Could not open file"));
1550 g_object_unref (gio_uri
);
1554 /* Crude way of loading, but faster */
1555 result
= g_input_stream_read_all (G_INPUT_STREAM (stream
),
1556 buffer
, size
, &nchars
, NULL
, NULL
);
1560 *err
= g_strdup (_("Error while reading from file"));
1561 g_object_unref (gio_uri
);
1568 buffer
[size
] = '\0';
1569 file_content
= g_strdup (buffer
);
1574 /* DEBUG_PRINT ("File size and loaded size not matching"); */
1577 g_settings_get_boolean (te
->settings
,
1580 /* Set editor mode */
1581 editor_mode
= determine_editor_mode (buffer
, nchars
);
1582 scintilla_send_message (SCINTILLA (te
->scintilla
),
1583 SCI_SETEOLMODE
, editor_mode
, 0);
1585 /* DEBUG_PRINT ("Loaded in editor mode [%d]", editor_mode); */
1587 /* Determine character encoding and convert to utf-8*/
1590 if (g_utf8_validate (buffer
, nchars
, NULL
))
1592 te
->encoding
= NULL
;
1596 gchar
*converted_text
;
1598 converted_text
= convert_to_utf8 (te
->props_base
,
1599 buffer
, nchars
, &te
->encoding
);
1601 if (converted_text
== NULL
)
1605 g_free (file_content
);
1606 *err
= g_strdup (_("The file does not look like a text file or the file encoding is not supported."
1607 " Please check if the encoding of file is in the supported encodings list."
1608 " If not, add it from the preferences."));
1609 g_object_unref (gio_uri
);
1614 buffer
= converted_text
;
1615 nchars
= strlen (converted_text
);
1618 if (dos_filter
&& editor_mode
== SC_EOL_CRLF
){
1619 /* DEBUG_PRINT ("Filtering Extrageneous DOS characters in dos mode [Dos => Unix]"); */
1620 nchars
= filter_chars_in_dos_mode( buffer
, nchars
);
1622 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_ADDTEXT
,
1623 nchars
, (long) buffer
);
1627 /* Save the buffer as last saved content */
1628 g_free (te
->last_saved_content
);
1629 te
->last_saved_content
= file_content
;
1631 g_object_unref (gio_uri
);
1637 strip_trailing_space (gchar
*data
, gsize
*size
)
1642 /* Search first trailing space */
1643 for (len
= 0;;len
++)
1645 while ((len
!= *size
) && (data
[len
] != ' ') && (data
[len
] != '\t')) len
++;
1646 if (len
== *size
) break;
1648 while ((len
!= *size
) && ((data
[len
] == ' ') || (data
[len
] == '\t'))) len
++;
1649 if ((len
== *size
) || (data
[len
] == '\n') || (data
[len
] == '\r'))
1651 gchar
*strip
= space
;
1653 /* Search next trailing space */
1656 while ((len
!= *size
) && (data
[len
] != ' ') && (data
[len
] != '\t')) *strip
++ = data
[len
++];
1657 if (len
== *size
) break;
1659 while ((len
!= *size
) && ((data
[len
] == ' ') || (data
[len
] == '\t'))) *strip
++ = data
[len
++];
1660 if ((len
== *size
) || (data
[len
] == '\n') || (data
[len
] == '\r'))
1662 strip
-= (&data
[len
] - space
);
1665 *size
-= (&data
[len
] - strip
);
1673 save_to_file (TextEditor
*te
, gchar
*uri
, GError
**error
)
1675 GFileOutputStream
*stream
;
1682 gio_uri
= g_file_new_for_uri (uri
);
1683 stream
= g_file_replace (gio_uri
, NULL
, FALSE
, G_FILE_CREATE_NONE
, NULL
, error
);
1690 nchars
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1691 SCI_GETLENGTH
, 0, 0);
1692 data
= (gchar
*) aneditor_command (te
->editor_id
,
1693 ANE_GETTEXTRANGE
, 0, nchars
);
1696 gint dos_filter
, editor_mode
;
1698 size
= strlen (data
);
1701 /* Save in original encoding */
1702 if ((te
->encoding
!= NULL
))
1704 GError
*conv_error
= NULL
;
1705 gchar
* converted_file_contents
= NULL
;
1708 /* DEBUG_PRINT ("Using encoding %s", te->encoding); */
1710 /* Try to convert it from UTF-8 to original encoding */
1711 converted_file_contents
= anjuta_convert_from_utf8 (data
, -1,
1716 if (conv_error
!= NULL
)
1718 /* Conversion error */
1719 g_error_free (conv_error
);
1724 data
= converted_file_contents
;
1725 size
= strlen (converted_file_contents
);
1731 /* DEBUG_PRINT ("Using utf-8 encoding"); */
1734 /* Strip trailing spaces */
1735 strip
= g_settings_get_boolean (te
->settings
,
1736 STRIP_TRAILING_SPACES
);
1739 strip_trailing_space (data
, &size
);
1741 if ((size
> 1) && ('\n' != data
[size
-1]))
1746 dos_filter
= g_settings_get_boolean (te
->settings
,
1748 editor_mode
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1749 SCI_GETEOLMODE
, 0, 0);
1750 /* DEBUG_PRINT ("Saving in editor mode [%d]", editor_mode); */
1752 if (editor_mode
== SC_EOL_CRLF
&& dos_filter
)
1754 /* DEBUG_PRINT ("Filtering Extrageneous DOS characters in dos mode [Unix => Dos]"); */
1755 size
= save_filtered_in_dos_mode (stream
, data
, size
);
1759 result
= g_output_stream_write_all (G_OUTPUT_STREAM (stream
),
1761 &nchars
, NULL
, error
);
1766 /* Set last content saved to data */
1767 g_free (te
->last_saved_content
);
1768 te
->last_saved_content
= data
;
1771 result
= g_output_stream_close (G_OUTPUT_STREAM (stream
), NULL
, error
);
1773 g_output_stream_close (G_OUTPUT_STREAM (stream
), NULL
, NULL
);
1775 g_object_unref (gio_uri
);
1781 text_editor_load_file (TextEditor
* te
)
1785 if (te
== NULL
|| te
->filename
== NULL
)
1787 if (IS_SCINTILLA (te
->scintilla
) == FALSE
)
1789 anjuta_status (te
->status
, _("Loading file..."), 5);
1791 text_editor_freeze (te
);
1793 // te->modified_time = time (NULL);
1794 text_editor_update_monitor (te
, FALSE
);
1795 if (load_from_file (te
, te
->uri
, &err
) == FALSE
)
1797 anjuta_util_dialog_error (NULL
,
1798 _("Could not load file: %s\n\nDetails: %s"),
1801 text_editor_thaw (te
);
1804 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GOTOPOS
,
1806 // check_tm_file(te);
1807 text_editor_thaw (te
);
1808 te
->force_not_saved
= FALSE
;
1809 scintilla_send_message (SCINTILLA (te
->scintilla
),
1810 SCI_SETSAVEPOINT
, 0, 0);
1811 scintilla_send_message (SCINTILLA (te
->scintilla
),
1812 SCI_EMPTYUNDOBUFFER
, 0, 0);
1813 text_editor_set_hilite_type (te
, NULL
);
1814 if (g_settings_get_boolean (te
->settings
, FOLD_ON_OPEN
))
1816 aneditor_command (te
->editor_id
, ANE_CLOSE_FOLDALL
, 0, 0);
1818 text_editor_set_line_number_width(te
);
1819 anjuta_status (te
->status
, _("File loaded successfully"), 5);
1821 g_idle_add ((GSourceFunc
) emit_opened
, te
);
1827 text_editor_save_file (TextEditor
* te
, gboolean update
)
1830 GError
*error
= NULL
;
1831 gboolean ret
= FALSE
;
1833 g_return_val_if_fail (te
!= NULL
, FALSE
);
1834 g_return_val_if_fail (IS_SCINTILLA (te
->scintilla
), FALSE
);
1836 text_editor_freeze (te
);
1837 text_editor_set_line_number_width(te
);
1838 parent
= GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (te
)));
1840 anjuta_status (te
->status
, _("Saving file..."), 5);
1841 text_editor_update_monitor (te
, TRUE
);
1843 if (!save_to_file (te
, te
->uri
, &error
))
1845 text_editor_thaw (te
);
1846 g_return_val_if_fail (error
!= NULL
, FALSE
);
1848 anjuta_util_dialog_error (parent
,
1849 _("Could not save intermediate file %s: %s"),
1852 g_signal_emit_by_name (G_OBJECT (te
), "saved", NULL
);
1853 g_error_free (error
);
1857 GFile
* file
= g_file_new_for_uri (te
->uri
);
1858 /* we need to update UI with the call to scintilla */
1859 text_editor_thaw (te
);
1860 te
->force_not_saved
= FALSE
;
1861 scintilla_send_message (SCINTILLA (te
->scintilla
),
1862 SCI_SETSAVEPOINT
, 0, 0);
1863 g_signal_emit_by_name (G_OBJECT (te
), "saved", file
);
1864 g_object_unref (file
);
1865 anjuta_status (te
->status
, _("File saved successfully"), 5);
1868 text_editor_update_monitor (te
, FALSE
);
1874 text_editor_set_saved (TextEditor
*te
, gboolean saved
)
1878 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_SETSAVEPOINT
, 0, 0);
1880 te
->force_not_saved
= !saved
;
1881 g_signal_emit_by_name(G_OBJECT (te
), "update-save-ui");
1885 text_editor_save_yourself (TextEditor
* te
, FILE * stream
)
1891 text_editor_recover_yourself (TextEditor
* te
, FILE * stream
)
1897 text_editor_undo (TextEditor
* te
)
1899 scintilla_send_message (SCINTILLA (te
->scintilla
),
1904 text_editor_redo (TextEditor
* te
)
1906 scintilla_send_message (SCINTILLA (te
->scintilla
),
1911 text_editor_update_controls (TextEditor
* te
)
1914 gboolean F
, P
, L
, C
, S
;
1918 S
= text_editor_is_saved (te
);
1919 L
= anjuta_launcher_is_busy (app
->launcher
);
1920 P
= app
->project_dbase
->project_is_open
;
1922 switch (get_file_ext_type (te
->filename
))
1932 switch (get_file_ext_type (te
->filename
))
1936 case FILE_TYPE_HEADER
:
1942 gtk_widget_set_sensitive (te
->buttons
.save
, !S
);
1943 gtk_widget_set_sensitive (te
->buttons
.reload
,
1945 gtk_widget_set_sensitive (te
->buttons
.compile
, F
&& !L
);
1946 gtk_widget_set_sensitive (te
->buttons
.build
, (F
|| P
) && !L
);
1951 text_editor_is_saved (TextEditor
* te
)
1953 return !(scintilla_send_message (SCINTILLA (te
->scintilla
),
1954 SCI_GETMODIFY
, 0, 0)) && (!te
->force_not_saved
);
1958 text_editor_has_selection (TextEditor
* te
)
1961 from
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1962 SCI_GETSELECTIONSTART
, 0, 0);
1963 to
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1964 SCI_GETSELECTIONEND
, 0, 0);
1965 return (from
== to
) ? FALSE
: TRUE
;
1968 glong
text_editor_get_selection_start (TextEditor
* te
)
1970 return scintilla_send_message (SCINTILLA (te
->scintilla
),
1971 SCI_GETSELECTIONSTART
, 0, 0);
1974 glong
text_editor_get_selection_end (TextEditor
* te
)
1976 return scintilla_send_message (SCINTILLA (te
->scintilla
),
1977 SCI_GETSELECTIONEND
, 0, 0);
1981 text_editor_get_selection (TextEditor
* te
)
1984 struct Sci_TextRange tr
;
1986 from
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1987 SCI_GETSELECTIONSTART
, 0, 0);
1988 to
= scintilla_send_message (SCINTILLA (te
->scintilla
),
1989 SCI_GETSELECTIONEND
, 0, 0);
1992 tr
.chrg
.cpMin
= MIN(from
, to
);
1993 tr
.chrg
.cpMax
= MAX(from
, to
);
1994 tr
.lpstrText
= g_malloc (sizeof(gchar
)*(tr
.chrg
.cpMax
-tr
.chrg
.cpMin
)+5);
1995 scintilla_send_message (SCINTILLA(te
->scintilla
), SCI_GETTEXTRANGE
, 0, (long)(&tr
));
1996 return tr
.lpstrText
;
2000 text_editor_is_marker_set (TextEditor
* te
, glong line
, gint marker
)
2004 g_return_val_if_fail (te
!= NULL
, FALSE
);
2005 g_return_val_if_fail (line
>= 0, FALSE
);
2006 g_return_val_if_fail (marker
< 32, FALSE
);
2008 state
= scintilla_send_message (SCINTILLA(te
->scintilla
),
2009 SCI_MARKERGET
, linenum_text_editor_to_scintilla (line
), 0);
2010 return ((state
& (1 << marker
)));
2014 text_editor_delete_marker_all (TextEditor
*te
, gint marker
)
2016 g_return_if_fail (IS_TEXT_EDITOR (te
));
2017 g_return_if_fail (marker
< 32);
2018 scintilla_send_message (SCINTILLA (te
->scintilla
),
2019 SCI_MARKERDELETEALL
, marker
, 0);
2023 text_editor_delete_marker (TextEditor
* te
, glong line
, gint marker
)
2025 g_return_if_fail (IS_TEXT_EDITOR (te
));
2026 g_return_if_fail (line
>= 0);
2027 g_return_if_fail (marker
< 32);
2029 scintilla_send_message (SCINTILLA(te
->scintilla
),
2030 SCI_MARKERDELETE
, linenum_text_editor_to_scintilla (line
), marker
);
2034 text_editor_line_from_handle (TextEditor
* te
, gint marker_handle
)
2038 g_return_val_if_fail (te
!= NULL
, -1);
2040 line
= scintilla_send_message (SCINTILLA(te
->scintilla
),
2041 SCI_MARKERLINEFROMHANDLE
, marker_handle
, 0);
2043 return linenum_scintilla_to_text_editor (line
);
2047 text_editor_get_bookmark_line( TextEditor
* te
, const glong nLineStart
)
2049 return aneditor_command (te
->editor_id
, ANE_GETBOOKMARK_POS
, nLineStart
, 0);
2053 text_editor_get_num_bookmarks(TextEditor
* te
)
2058 g_return_val_if_fail (te
!= NULL
, 0 );
2060 while( ( nLineNo
= text_editor_get_bookmark_line( te
, nLineNo
) ) >= 0 )
2062 //printf( "Line %d\n", nLineNo );
2065 //printf( "out Line %d\n", nLineNo );
2069 /* Gets the word before just before carat */
2071 text_editor_get_word_before_carat (TextEditor
*te
)
2075 aneditor_command (TEXT_EDITOR (te
)->editor_id
,
2076 ANE_GETWORDBEFORECARAT
, (glong
) buffer
, 512);
2077 if (buffer
[0] != '\0')
2078 return g_strdup (buffer
);
2084 *Get the current selection. If there is no selection, or if the selection
2085 * is all blanks, get the word under teh cursor.
2088 text_editor_get_current_word (TextEditor
*te
)
2090 char *buf
= text_editor_get_selection(te
);
2103 buf
= g_new(char, 256);
2104 ret
= aneditor_command (te
->editor_id
, ANE_GETCURRENTWORD
, (long)buf
, 255L);
2114 DEBUG_PRINT ("Current word is '%s'", buf);
2121 text_editor_function_select(TextEditor
*te
)
2130 line_count
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2131 SCI_GETLINECOUNT
, 0, 0);
2132 pos
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2133 SCI_GETCURRENTPOS
, 0, 0);
2134 line
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2135 SCI_LINEFROMPOSITION
, pos
, 0);
2138 fold_level
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2139 SCI_GETFOLDLEVEL
, line
, 0) ;
2140 if ((fold_level
& 0xFF) != 0)
2142 while((fold_level
& 0x10FF) != 0x1000 && line
>= 0)
2143 fold_level
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2144 SCI_GETFOLDLEVEL
, --line
, 0) ;
2145 start
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2146 SCI_POSITIONFROMLINE
, line
+ 1, 0);
2148 fold_level
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2149 SCI_GETFOLDLEVEL
, line
, 0) ;
2150 while((fold_level
& 0x10FF) != 0x1000 && line
< line_count
)
2151 fold_level
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2152 SCI_GETFOLDLEVEL
, ++line
, 0) ;
2154 end
= scintilla_send_message(SCINTILLA(te
->scintilla
),
2155 SCI_POSITIONFROMLINE
, line
, 0);
2156 scintilla_send_message(SCINTILLA(te
->scintilla
),
2157 SCI_SETSEL
, start
, end
) ;
2162 text_editor_grab_focus (TextEditor
*te
)
2164 g_return_if_fail (IS_TEXT_EDITOR (te
));
2165 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GRABFOCUS
, 0, 0);
2169 text_editor_set_popup_menu (TextEditor
*te
, GtkWidget
*popup_menu
)
2172 g_object_ref (popup_menu
);
2174 g_object_unref (te
->popup_menu
);
2175 te
->popup_menu
= popup_menu
;
2179 text_editor_set_busy (TextEditor
*te
, gboolean state
)
2182 scintilla_send_message (SCINTILLA (te
->scintilla
),
2183 SCI_SETCURSOR
, SC_CURSORWAIT
, 0);
2185 scintilla_send_message (SCINTILLA (te
->scintilla
),
2186 SCI_SETCURSOR
, SC_CURSORNORMAL
, 0);
2190 text_editor_get_props ()
2192 /* Built in values */
2193 static PropsID props_built_in
= 0;
2196 static PropsID props_global
= 0;
2199 // static PropsID props_local = 0;
2201 /* Session values */
2202 static PropsID props_session
= 0;
2204 /* Instance values */
2205 static PropsID props
= 0;
2207 gchar
*propdir
, *propfile
;
2212 props_built_in
= sci_prop_set_new ();
2213 props_global
= sci_prop_set_new ();
2214 // props_local = sci_prop_set_new ();
2215 props_session
= sci_prop_set_new ();
2216 props
= sci_prop_set_new ();
2218 sci_prop_clear (props_built_in
);
2219 sci_prop_clear (props_global
);
2220 // sci_prop_clear (props_local);
2221 sci_prop_clear (props_session
);
2222 sci_prop_clear (props
);
2224 sci_prop_set_parent (props_global
, props_built_in
);
2225 // sci_prop_set_parent (props_local, props_global);
2226 // sci_prop_set_parent (props_session, props_local);
2227 sci_prop_set_parent (props_session
, props_global
);
2228 sci_prop_set_parent (props
, props_session
);
2230 propdir
= g_build_filename (PACKAGE_DATA_DIR
, "properties/", NULL
);
2231 propfile
= g_build_filename (PACKAGE_DATA_DIR
, "properties",
2232 "anjuta.properties", NULL
);
2233 /* DEBUG_PRINT ("Reading file: %s", propfile); */
2235 if (g_file_test (propfile
, G_FILE_TEST_EXISTS
) == FALSE
)
2237 anjuta_util_dialog_error (NULL
,
2238 _("Cannot load Global defaults and configuration files:\n"
2240 "This may result in improper behaviour or instabilities.\n"
2241 "Anjuta will fall back to built in (limited) settings"),
2244 sci_prop_read (props_global
, propfile
, propdir
);
2248 propdir
= anjuta_util_get_user_config_file_path ("scintilla/",NULL
);
2249 propfile
= anjuta_util_get_user_config_file_path ("scintilla","editor-style.properties",NULL
);
2250 /* DEBUG_PRINT ("Reading file: %s", propfile); */
2252 /* Create user.properties file, if it doesn't exist */
2253 if (g_file_test (propfile
, G_FILE_TEST_EXISTS
) == FALSE
) {
2254 gchar
* old_propfile
= anjuta_util_get_user_config_file_path ("scintilla", "session.properties", NULL
);
2255 if (g_file_test (old_propfile
, G_FILE_TEST_EXISTS
) == TRUE
)
2256 anjuta_util_copy_file (old_propfile
, propfile
, FALSE
);
2257 g_free (old_propfile
);
2259 sci_prop_read (props_session
, propfile
, propdir
);
2267 text_editor_set_line_number_width (TextEditor
* te
)
2269 /* Set line numbers with according to file size */
2270 if (g_settings_get_boolean (te
->settings
,
2271 VIEW_LINENUMBERS_MARGIN
))
2273 int lines
, line_number_width
;
2275 gchar
* line_number_dummy
;
2278 (int) scintilla_send_message
2279 (SCINTILLA(te
->scintilla
), SCI_GETLINECOUNT
, 0,0);
2280 line_number
= g_strdup_printf("%d", lines
);
2281 line_number_dummy
= g_strnfill(strlen(line_number
) + 1, '9');
2283 (int) scintilla_send_message (SCINTILLA(te
->scintilla
),
2286 (long) line_number_dummy
);
2287 text_editor_command (te
, ANE_SETLINENUMWIDTH
, line_number_width
, 0);
2288 g_free(line_number_dummy
);
2289 g_free(line_number
);
2294 text_editor_can_undo (TextEditor
*te
)
2296 g_return_val_if_fail (IS_TEXT_EDITOR (te
), FALSE
);
2297 return scintilla_send_message (SCINTILLA (te
->scintilla
),
2302 text_editor_can_redo (TextEditor
*te
)
2304 g_return_val_if_fail (IS_TEXT_EDITOR (te
), FALSE
);
2305 return scintilla_send_message (SCINTILLA (te
->scintilla
),
2310 text_editor_show_hover_tip (TextEditor
*te
, gint position
, const gchar
*info
)
2312 text_editor_hide_hover_tip (te
);
2313 if (!te
->hover_tip_on
)
2315 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_CALLTIPSHOW
,
2316 position
, (long)info
);
2317 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_CALLTIPSETHLT
,
2319 te
->hover_tip_on
= TRUE
;
2324 text_editor_hide_hover_tip (TextEditor
*te
)
2326 if (te
->hover_tip_on
)
2328 scintilla_send_message (SCINTILLA (te
->scintilla
),
2329 SCI_CALLTIPCANCEL
, 0, 0);
2330 te
->hover_tip_on
= FALSE
;
2335 text_editor_cancel_completion (TextEditor
*te
)
2337 te
->completion_count
= 0;
2338 g_string_truncate (te
->completion_string
, 0);
2342 text_editor_suggest_completion (TextEditor
*te
)
2345 TextEditorCell
*iter
;
2348 position
= text_editor_get_current_position (te
);
2349 iter
= text_editor_cell_new (te
, position
);
2350 for (node
= te
->provider
; node
!= NULL
; node
= g_list_next (node
))
2352 ianjuta_provider_populate (IANJUTA_PROVIDER (node
->data
), IANJUTA_ITERABLE (iter
), NULL
);
2354 g_object_unref (iter
);
2358 text_editor_select_completion (TextEditor
*te
)
2360 TextEditorCell
*iter
;
2364 autoc_sel
= (gint
) scintilla_send_message (SCINTILLA (te
->scintilla
),
2365 SCI_AUTOCGETCURRENT
,
2367 scintilla_send_message (SCINTILLA (te
->scintilla
),
2368 SCI_AUTOCCANCEL
, 0, 0);
2370 g_return_if_fail (autoc_sel
< te
->completion_count
);
2372 position
= text_editor_get_current_position (te
);
2373 iter
= text_editor_cell_new (te
, position
);
2375 ianjuta_provider_activate (IANJUTA_PROVIDER (te
->completion
[autoc_sel
].provider
),
2376 IANJUTA_ITERABLE (iter
),
2377 te
->completion
[autoc_sel
].data
, NULL
);
2378 g_object_unref (iter
);
2382 text_editor_command (TextEditor
*te
, gint command
, glong wparam
, glong lparam
)
2389 aneditor_command (GPOINTER_TO_INT (node
->data
), command
, wparam
, lparam
);
2390 node
= g_list_next(node
);
2395 text_editor_scintilla_command (TextEditor
*te
, gint command
, glong wparam
,
2403 GtkWidget
*scintilla
;
2404 scintilla
= aneditor_get_widget (GPOINTER_TO_INT (node
->data
));
2405 scintilla_send_message (SCINTILLA(scintilla
), command
, wparam
, lparam
);
2406 node
= g_list_next(node
);
2410 /* IAnjutaEditor interface implementation */
2413 itext_editor_get_tab_size (IAnjutaEditor
*editor
, GError
**e
)
2415 return scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2416 SCI_GETTABWIDTH
, 0, 0);
2420 itext_editor_set_tab_size (IAnjutaEditor
*editor
, gint tabsize
, GError
**e
)
2422 scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2423 SCI_SETTABWIDTH
, tabsize
, 0);
2427 itext_editor_get_use_spaces (IAnjutaEditor
*editor
, GError
**e
)
2429 return !scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2430 SCI_GETUSETABS
, 0, 0);
2434 itext_editor_set_use_spaces (IAnjutaEditor
*editor
, gboolean use_spaces
, GError
**e
)
2436 scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2437 SCI_SETUSETABS
, !use_spaces
, 0);
2440 /* This function does not set automatic indentation but allow or not
2441 * the editor to indent the text. Used to disable editor indentation when
2442 * another plugin take care of it. */
2444 itext_editor_set_auto_indent (IAnjutaEditor
*editor
, gboolean auto_indent
, GError
**e
)
2446 text_editor_command (TEXT_EDITOR(editor
), ANE_SETAUTOINDENTATION
, auto_indent
, 0);
2450 itext_editor_get_indent_size (IAnjutaEditor
*editor
, GError
**e
)
2452 return scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2453 SCI_GETINDENT
, 0, 0);
2457 itext_editor_set_indent_size (IAnjutaEditor
*editor
, gint indentsize
, GError
**e
)
2459 scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2460 SCI_SETINDENT
, indentsize
, 0);
2464 itext_editor_goto_line (IAnjutaEditor
*editor
, gint lineno
, GError
**e
)
2466 text_editor_goto_line (TEXT_EDITOR (editor
), lineno
, FALSE
, TRUE
);
2467 gtk_widget_grab_focus (TEXT_EDITOR (editor
)->scintilla
);
2471 itext_editor_goto_start (IAnjutaEditor
*editor
, GError
**e
)
2473 text_editor_goto_point (TEXT_EDITOR (editor
), 0);
2477 itext_editor_goto_end (IAnjutaEditor
*editor
, GError
**e
)
2479 text_editor_goto_point (TEXT_EDITOR (editor
), -1);
2483 itext_editor_goto_position (IAnjutaEditor
*editor
, IAnjutaIterable
*position
,
2486 text_editor_goto_point (TEXT_EDITOR (editor
),
2487 text_editor_cell_get_position (TEXT_EDITOR_CELL
2492 itext_editor_get_text_all (IAnjutaEditor
*editor
, GError
**e
)
2494 TextEditor
*te
= TEXT_EDITOR (editor
);
2495 gint length
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2496 SCI_GETLENGTH
, 0, 0);
2498 return (gchar
*) aneditor_command (te
->editor_id
, ANE_GETTEXTRANGE
,
2505 itext_editor_get_text (IAnjutaEditor
*editor
, IAnjutaIterable
* begin
,
2506 IAnjutaIterable
* end
, GError
**e
)
2509 gint start_pos
= text_editor_cell_get_position (TEXT_EDITOR_CELL (begin
));
2510 gint end_pos
= text_editor_cell_get_position (TEXT_EDITOR_CELL (end
));
2511 TextEditor
*te
= TEXT_EDITOR (editor
);
2512 data
= (gchar
*) aneditor_command (te
->editor_id
, ANE_GETTEXTRANGE
,
2513 start_pos
, end_pos
);
2517 static IAnjutaIterable
*
2518 itext_editor_get_position (IAnjutaEditor
* editor
, GError
**e
)
2520 TextEditor
*te
= TEXT_EDITOR (editor
);
2521 gint position
= text_editor_get_current_position (te
);
2522 TextEditorCell
*position_iter
= text_editor_cell_new (te
, position
);
2523 return IANJUTA_ITERABLE (position_iter
);
2527 itext_editor_get_offset (IAnjutaEditor
*editor
, GError
**e
)
2530 IAnjutaIterable
*iter
= itext_editor_get_position (editor
, NULL
);
2531 pos
= ianjuta_iterable_get_position (iter
, NULL
);
2532 g_object_unref (iter
);
2537 itext_editor_get_lineno (IAnjutaEditor
*editor
, GError
**e
)
2539 return text_editor_get_current_lineno (TEXT_EDITOR (editor
));
2543 itext_editor_get_length (IAnjutaEditor
*editor
, GError
**e
)
2545 return aneditor_command (TEXT_EDITOR (editor
)->editor_id
,
2546 ANE_GETLENGTH
, 0, 0);
2550 itext_editor_get_current_word (IAnjutaEditor
*editor
, GError
**e
)
2554 aneditor_command (TEXT_EDITOR (editor
)->editor_id
,
2555 ANE_GETCURRENTWORD
, (glong
) buffer
, 512);
2556 if (buffer
[0] != '\0')
2557 return g_strdup (buffer
);
2563 itext_editor_insert (IAnjutaEditor
*editor
, IAnjutaIterable
*position
,
2564 const gchar
*txt
, gint length
, GError
**e
)
2566 gchar
*text_to_insert
;
2569 pos
= text_editor_cell_get_position (TEXT_EDITOR_CELL (position
));
2570 if (length
< 0) length
= strlen (txt
);
2572 text_to_insert
= g_strndup (txt
, length
);
2574 aneditor_command (TEXT_EDITOR(editor
)->editor_id
, ANE_INSERTTEXT
,
2575 pos
, (long)text_to_insert
);
2577 g_free (text_to_insert
);
2581 itext_editor_append (IAnjutaEditor
*editor
, const gchar
*txt
,
2582 gint length
, GError
**e
)
2584 gchar
*text_to_insert
;
2586 text_to_insert
= g_strndup (txt
, length
);
2588 text_to_insert
= g_strdup (txt
);
2590 scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2591 SCI_APPENDTEXT
, strlen(text_to_insert
),
2592 (long)text_to_insert
);
2593 g_free (text_to_insert
);
2597 itext_editor_erase (IAnjutaEditor
*editor
,
2598 IAnjutaIterable
*position_start
,
2599 IAnjutaIterable
*position_end
, GError
**e
)
2603 /* If both positions are NULL, erase all */
2604 if (position_start
== NULL
&& position_end
== NULL
)
2606 scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2612 /* Determine correct start and end byte positions */
2614 start
= text_editor_cell_get_position (TEXT_EDITOR_CELL (position_start
));
2619 end
= text_editor_cell_get_position (TEXT_EDITOR_CELL (position_end
));
2621 end
= scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2622 SCI_GETLENGTH
, 0, 0);
2625 scintilla_send_message (SCINTILLA(TEXT_EDITOR (editor
)->scintilla
),
2626 SCI_SETSEL
, start
, end
);
2627 text_editor_replace_selection (TEXT_EDITOR (editor
), "");
2632 itext_editor_erase_all (IAnjutaEditor
*editor
, GError
**e
)
2634 scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2640 itext_editor_get_column (IAnjutaEditor
*editor
, GError
**e
)
2642 return text_editor_get_current_column (TEXT_EDITOR(editor
));
2646 itext_editor_get_overwrite (IAnjutaEditor
*editor
, GError
**e
)
2648 return text_editor_get_overwrite (TEXT_EDITOR (editor
));
2652 itext_editor_set_popup_menu (IAnjutaEditor
*editor
, GtkWidget
* menu
, GError
**e
)
2654 text_editor_set_popup_menu (TEXT_EDITOR (editor
), menu
);
2658 itext_editor_get_line_from_position (IAnjutaEditor
*editor
,
2659 IAnjutaIterable
*position
, GError
**e
)
2661 return text_editor_get_line_from_position (TEXT_EDITOR (editor
),
2662 text_editor_cell_get_position (TEXT_EDITOR_CELL (position
)));
2665 static IAnjutaIterable
*
2666 itext_editor_get_line_begin_position (IAnjutaEditor
*editor
, gint line
,
2672 g_return_val_if_fail (line
> 0, NULL
);
2673 te
= TEXT_EDITOR (editor
);
2674 ln
= linenum_text_editor_to_scintilla (line
);
2675 byte_pos
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2676 SCI_POSITIONFROMLINE
, ln
, 0);
2677 return IANJUTA_ITERABLE (text_editor_cell_new (te
, byte_pos
));
2680 static IAnjutaIterable
*
2681 itext_editor_get_line_end_position (IAnjutaEditor
*editor
, gint line
,
2687 g_return_val_if_fail (line
> 0, NULL
);
2688 te
= TEXT_EDITOR (editor
);
2690 ln
= linenum_text_editor_to_scintilla (line
);
2691 byte_pos
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2692 SCI_GETLINEENDPOSITION
, ln
, 0);
2693 return IANJUTA_ITERABLE (text_editor_cell_new (te
, byte_pos
));
2696 static IAnjutaIterable
*
2697 itext_editor_get_position_from_offset (IAnjutaEditor
*editor
, gint offset
, GError
**e
)
2699 TextEditorCell
*editor_cell
= text_editor_cell_new (TEXT_EDITOR (editor
), 0);
2700 /* Set to the right utf8 character offset */
2701 ianjuta_iterable_set_position (IANJUTA_ITERABLE (editor_cell
), offset
, NULL
);
2702 return IANJUTA_ITERABLE (editor_cell
);
2705 static IAnjutaIterable
*
2706 itext_editor_get_start_position (IAnjutaEditor
*editor
, GError
**e
)
2708 TextEditorCell
*editor_cell
= text_editor_cell_new (TEXT_EDITOR (editor
), 0);
2709 return IANJUTA_ITERABLE (editor_cell
);
2712 static IAnjutaIterable
*
2713 itext_editor_get_end_position (IAnjutaEditor
*editor
, GError
**e
)
2715 gint length
= scintilla_send_message (SCINTILLA (TEXT_EDITOR (editor
)->scintilla
),
2716 SCI_GETLENGTH
, 0, 0);
2717 TextEditorCell
*editor_cell
= text_editor_cell_new (TEXT_EDITOR (editor
),
2719 return IANJUTA_ITERABLE (editor_cell
);
2723 itext_editor_iface_init (IAnjutaEditorIface
*iface
)
2725 iface
->get_tabsize
= itext_editor_get_tab_size
;
2726 iface
->set_tabsize
= itext_editor_set_tab_size
;
2727 iface
->get_use_spaces
= itext_editor_get_use_spaces
;
2728 iface
->set_use_spaces
= itext_editor_set_use_spaces
;
2729 iface
->set_auto_indent
= itext_editor_set_auto_indent
;
2730 iface
->get_indentsize
= itext_editor_get_indent_size
;
2731 iface
->set_indentsize
= itext_editor_set_indent_size
;
2732 iface
->goto_line
= itext_editor_goto_line
;
2733 iface
->goto_start
= itext_editor_goto_start
;
2734 iface
->goto_end
= itext_editor_goto_end
;
2735 iface
->goto_position
= itext_editor_goto_position
;
2736 iface
->get_text_all
= itext_editor_get_text_all
;
2737 iface
->get_text
= itext_editor_get_text
;
2738 iface
->get_offset
= itext_editor_get_offset
;
2739 iface
->get_position
= itext_editor_get_position
;
2740 iface
->get_lineno
= itext_editor_get_lineno
;
2741 iface
->get_length
= itext_editor_get_length
;
2742 iface
->get_current_word
= itext_editor_get_current_word
;
2743 iface
->insert
= itext_editor_insert
;
2744 iface
->append
= itext_editor_append
;
2745 iface
->erase
= itext_editor_erase
;
2746 iface
->erase_all
= itext_editor_erase_all
;
2747 iface
->get_column
= itext_editor_get_column
;
2748 iface
->get_overwrite
= itext_editor_get_overwrite
;
2749 iface
->set_popup_menu
= itext_editor_set_popup_menu
;
2750 iface
->get_line_from_position
= itext_editor_get_line_from_position
;
2751 iface
->get_line_begin_position
= itext_editor_get_line_begin_position
;
2752 iface
->get_line_end_position
= itext_editor_get_line_end_position
;
2753 iface
->get_position_from_offset
= itext_editor_get_position_from_offset
;
2754 iface
->get_start_position
= itext_editor_get_start_position
;
2755 iface
->get_end_position
= itext_editor_get_end_position
;
2758 static const gchar
*
2759 idocument_get_filename (IAnjutaDocument
*editor
, GError
**e
)
2761 return (TEXT_EDITOR (editor
))->filename
;
2765 idocument_can_undo(IAnjutaDocument
* editor
, GError
**e
)
2767 return text_editor_can_undo(TEXT_EDITOR(editor
));
2771 idocument_can_redo(IAnjutaDocument
*editor
, GError
**e
)
2773 return text_editor_can_redo(TEXT_EDITOR(editor
));
2777 idocument_undo(IAnjutaDocument
* te
, GError
** ee
)
2779 text_editor_command(TEXT_EDITOR(te
), ANE_UNDO
, 0, 0);
2783 idocument_begin_undo_action (IAnjutaDocument
* te
, GError
** ee
)
2785 scintilla_send_message (SCINTILLA (TEXT_EDITOR (te
)->scintilla
),
2786 SCI_BEGINUNDOACTION
, 0, 0);
2790 idocument_end_undo_action (IAnjutaDocument
* te
, GError
** ee
)
2792 scintilla_send_message (SCINTILLA (TEXT_EDITOR (te
)->scintilla
),
2793 SCI_ENDUNDOACTION
, 0, 0);
2797 idocument_redo(IAnjutaDocument
* te
, GError
** ee
)
2799 text_editor_command(TEXT_EDITOR(te
), ANE_REDO
, 0, 0);
2803 idocument_grab_focus (IAnjutaDocument
*editor
, GError
**e
)
2805 text_editor_grab_focus (TEXT_EDITOR (editor
));
2809 idocument_cut(IAnjutaDocument
* te
, GError
** ee
)
2811 text_editor_command(TEXT_EDITOR(te
), ANE_CUT
, 0, 0);
2815 idocument_copy(IAnjutaDocument
* te
, GError
** ee
)
2817 text_editor_command(TEXT_EDITOR(te
), ANE_COPY
, 0, 0);
2821 idocument_paste(IAnjutaDocument
* te
, GError
** ee
)
2823 text_editor_command(TEXT_EDITOR(te
), ANE_PASTE
, 0, 0);
2827 idocument_clear(IAnjutaDocument
* te
, GError
** ee
)
2829 text_editor_command(TEXT_EDITOR(te
), ANE_CLEAR
, 0, 0);
2833 idocument_iface_init(IAnjutaDocumentIface
* iface
)
2835 iface
->get_filename
= idocument_get_filename
;
2836 iface
->can_undo
= idocument_can_undo
;
2837 iface
->can_redo
= idocument_can_redo
;
2838 iface
->undo
= idocument_undo
;
2839 iface
->redo
= idocument_redo
;
2840 iface
->begin_undo_action
= idocument_begin_undo_action
;
2841 iface
->end_undo_action
= idocument_end_undo_action
;
2842 iface
->grab_focus
= idocument_grab_focus
;
2843 iface
->cut
= idocument_cut
;
2844 iface
->copy
= idocument_copy
;
2845 iface
->paste
= idocument_paste
;
2846 iface
->clear
= idocument_clear
;
2849 /* IAnjutaEditorSelection implementation */
2852 iselection_get (IAnjutaEditorSelection
*editor
, GError
**error
)
2854 return text_editor_get_selection (TEXT_EDITOR (editor
));
2858 iselection_set (IAnjutaEditorSelection
* edit
,
2859 IAnjutaIterable
* istart
,
2860 IAnjutaIterable
* iend
,
2861 gboolean scroll
, /* TODO: Is is possible to set this in scintilla? */
2864 TextEditorCell
* start
= TEXT_EDITOR_CELL (istart
);
2865 TextEditorCell
* end
= TEXT_EDITOR_CELL (iend
);
2866 int start_pos
= text_editor_cell_get_position (start
);
2867 int end_pos
= text_editor_cell_get_position (end
);
2869 /* Keep current position at the beginning of the selection like GtkSourceView */
2870 scintilla_send_message (SCINTILLA (TEXT_EDITOR (edit
)->scintilla
),
2871 SCI_SETSEL
, end_pos
, start_pos
);
2875 iselection_has_selection (IAnjutaEditorSelection
*editor
, GError
**e
)
2877 return text_editor_has_selection (TEXT_EDITOR (editor
));
2880 static IAnjutaIterable
*
2881 iselection_get_start (IAnjutaEditorSelection
*edit
, GError
**e
)
2883 gint start
= scintilla_send_message (SCINTILLA(TEXT_EDITOR(edit
)->scintilla
),
2884 SCI_GETSELECTIONSTART
, 0, 0);
2885 gint end
= scintilla_send_message (SCINTILLA(TEXT_EDITOR(edit
)->scintilla
),
2886 SCI_GETSELECTIONEND
, 0, 0);
2889 return IANJUTA_ITERABLE (text_editor_cell_new (TEXT_EDITOR (edit
), start
));
2895 static IAnjutaIterable
*
2896 iselection_get_end (IAnjutaEditorSelection
*edit
, GError
**e
)
2898 gint start
= scintilla_send_message (SCINTILLA(TEXT_EDITOR(edit
)->scintilla
),
2899 SCI_GETSELECTIONSTART
, 0, 0);
2900 gint end
= scintilla_send_message (SCINTILLA(TEXT_EDITOR(edit
)->scintilla
),
2901 SCI_GETSELECTIONEND
, 0, 0);
2904 return IANJUTA_ITERABLE (text_editor_cell_new (TEXT_EDITOR (edit
), end
));
2911 iselection_replace (IAnjutaEditorSelection
*editor
, const gchar
*txt
,
2912 gint length
, GError
**e
)
2914 gchar
*text_to_insert
;
2916 text_to_insert
= g_strndup (txt
, length
);
2918 text_to_insert
= g_strdup (txt
);
2920 text_editor_replace_selection (TEXT_EDITOR (editor
), text_to_insert
);
2922 g_free (text_to_insert
);
2926 iselection_select_all (IAnjutaEditorSelection
* te
, GError
** ee
)
2928 text_editor_command (TEXT_EDITOR (te
), ANE_SELECTALL
, 0, 0);
2932 iselection_select_block (IAnjutaEditorSelection
*te
, GError
**e
)
2934 text_editor_command (TEXT_EDITOR(te
), ANE_SELECTBLOCK
, 0, 0);
2938 iselection_select_function (IAnjutaEditorSelection
*editor
, GError
**e
)
2940 TextEditor
* te
= TEXT_EDITOR(editor
);
2948 line_count
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2949 SCI_GETLINECOUNT
, 0, 0);
2950 pos
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2951 SCI_GETCURRENTPOS
, 0, 0);
2952 line
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2953 SCI_LINEFROMPOSITION
, pos
, 0);
2956 fold_level
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2957 SCI_GETFOLDLEVEL
, line
, 0) ;
2958 if ((fold_level
& 0xFF) != 0)
2960 while ((fold_level
& 0x10FF) != 0x1000 && line
>= 0)
2961 fold_level
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2962 SCI_GETFOLDLEVEL
, --line
, 0) ;
2963 start
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2964 SCI_POSITIONFROMLINE
, line
+ 1, 0);
2966 fold_level
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2967 SCI_GETFOLDLEVEL
, line
, 0) ;
2968 while ((fold_level
& 0x10FF) != 0x1000 && line
< line_count
)
2969 fold_level
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2970 SCI_GETFOLDLEVEL
, ++line
, 0) ;
2972 end
= scintilla_send_message (SCINTILLA (te
->scintilla
),
2973 SCI_POSITIONFROMLINE
, line
, 0);
2974 scintilla_send_message (SCINTILLA (te
->scintilla
),
2975 SCI_SETSEL
, start
, end
) ;
2980 iselection_iface_init (IAnjutaEditorSelectionIface
*iface
)
2982 iface
->has_selection
= iselection_has_selection
;
2983 iface
->get
= iselection_get
;
2984 iface
->set
= iselection_set
;
2985 iface
->get_start
= iselection_get_start
;
2986 iface
->get_end
= iselection_get_end
;
2987 iface
->replace
= iselection_replace
;
2988 iface
->select_all
= iselection_select_all
;
2989 iface
->select_block
= iselection_select_block
;
2990 iface
->select_function
= iselection_select_function
;
2993 /* IAnjutaFile implementation */
2996 ifile_get_file (IAnjutaFile
*editor
, GError
**error
)
2998 TextEditor
*text_editor
;
2999 text_editor
= TEXT_EDITOR(editor
);
3000 if (text_editor
->uri
)
3001 return g_file_new_for_uri (text_editor
->uri
);
3007 ifile_open (IAnjutaFile
*editor
, GFile
* file
, GError
**error
)
3009 /* Close current file and open new file in this editor */
3010 TextEditor
* text_editor
;
3011 text_editor
= TEXT_EDITOR(editor
);
3014 g_free (text_editor
->uri
);
3015 text_editor
->uri
= g_file_get_uri (file
);
3016 g_free (text_editor
->filename
);
3017 text_editor
->filename
= g_file_get_basename (file
);
3018 text_editor_load_file (text_editor
);
3022 isaveable_save (IAnjutaFileSavable
* editor
, GError
** e
)
3024 TextEditor
*text_editor
= TEXT_EDITOR(editor
);
3026 if (text_editor
->uri
!= NULL
)
3027 text_editor_save_file(text_editor
, FALSE
);
3029 g_signal_emit_by_name (G_OBJECT (text_editor
), "saved", NULL
);
3033 isavable_save_as (IAnjutaFileSavable
* editor
, GFile
* file
, GError
** e
)
3035 const gchar
*past_language
;
3036 const gchar
*curr_language
;
3037 TextEditor
*text_editor
= TEXT_EDITOR(editor
);
3040 ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (text_editor
),
3044 g_free (text_editor
->uri
);
3045 text_editor
->uri
= g_file_get_uri (file
);
3046 g_free (text_editor
->filename
);
3047 text_editor
->filename
= g_file_get_basename (file
);
3048 text_editor_save_file (text_editor
, FALSE
);
3049 text_editor_set_hilite_type (text_editor
, NULL
);
3050 text_editor_hilite (text_editor
, FALSE
);
3052 /* We have to take care of 'language-change' signal ourself because
3053 * text_editor_set_hilite_type() only emits it for forced hilite type
3056 ianjuta_editor_language_get_language (IANJUTA_EDITOR_LANGUAGE (text_editor
),
3058 if (past_language
!= curr_language
)
3059 g_signal_emit_by_name (text_editor
, "language-changed", curr_language
);
3064 isavable_is_dirty (IAnjutaFileSavable
* editor
, GError
** e
)
3066 TextEditor
*text_editor
= TEXT_EDITOR(editor
);
3067 return !text_editor_is_saved (text_editor
);
3071 isavable_set_dirty (IAnjutaFileSavable
* editor
, gboolean dirty
, GError
** e
)
3073 TextEditor
*text_editor
= TEXT_EDITOR(editor
);
3074 text_editor_set_saved (text_editor
, !dirty
);
3078 isavable_is_read_only (IAnjutaFileSavable
* savable
, GError
** e
)
3085 isavable_is_conflict (IAnjutaFileSavable
* savable
, GError
** e
)
3087 TextEditor
*te
= TEXT_EDITOR(savable
);
3088 return te
->message_area
!= NULL
;
3092 isavable_iface_init (IAnjutaFileSavableIface
*iface
)
3094 iface
->save
= isaveable_save
;
3095 iface
->save_as
= isavable_save_as
;
3096 iface
->set_dirty
= isavable_set_dirty
;
3097 iface
->is_dirty
= isavable_is_dirty
;
3098 iface
->is_read_only
= isavable_is_read_only
;
3099 iface
->is_conflict
= isavable_is_conflict
;
3103 ifile_iface_init (IAnjutaFileIface
*iface
)
3105 iface
->open
= ifile_open
;
3106 iface
->get_file
= ifile_get_file
;
3109 /* Implementation of the IAnjutaMarkable interface */
3112 marker_ianjuta_to_editor (IAnjutaMarkableMarker marker
)
3117 case IANJUTA_MARKABLE_LINEMARKER
:
3118 mark
= TEXT_EDITOR_LINEMARKER
;
3120 case IANJUTA_MARKABLE_BOOKMARK
:
3121 mark
= TEXT_EDITOR_BOOKMARK
;
3123 case IANJUTA_MARKABLE_BREAKPOINT_DISABLED
:
3124 mark
= TEXT_EDITOR_BREAKPOINT_DISABLED
;
3126 case IANJUTA_MARKABLE_BREAKPOINT_ENABLED
:
3127 mark
= TEXT_EDITOR_BREAKPOINT_ENABLED
;
3129 case IANJUTA_MARKABLE_PROGRAM_COUNTER
:
3130 mark
= TEXT_EDITOR_PROGRAM_COUNTER
;
3133 mark
= TEXT_EDITOR_LINEMARKER
;
3139 imarkable_mark (IAnjutaMarkable
* editor
, gint location
,
3140 IAnjutaMarkableMarker marker
, const gchar
*tooltip
, GError
** e
)
3142 return text_editor_set_marker (TEXT_EDITOR (editor
), location
,
3143 marker_ianjuta_to_editor (marker
));
3147 imarkable_location_from_handle (IAnjutaMarkable
* editor
, gint handle
, GError
** e
)
3149 return text_editor_line_from_handle (TEXT_EDITOR (editor
), handle
);
3153 imarkable_unmark (IAnjutaMarkable
* editor
, gint location
,
3154 IAnjutaMarkableMarker marker
, GError
** e
)
3156 text_editor_delete_marker (TEXT_EDITOR (editor
), location
,
3157 marker_ianjuta_to_editor (marker
));
3161 imarkable_is_marker_set (IAnjutaMarkable
* editor
, gint location
,
3162 IAnjutaMarkableMarker marker
, GError
** e
)
3164 return text_editor_is_marker_set (TEXT_EDITOR (editor
), location
,
3165 marker_ianjuta_to_editor (marker
));
3169 imarkable_delete_all_markers (IAnjutaMarkable
* editor
,
3170 IAnjutaMarkableMarker marker
, GError
** e
)
3172 text_editor_delete_marker_all (TEXT_EDITOR (editor
),
3173 marker_ianjuta_to_editor (marker
));
3177 imarkable_iface_init (IAnjutaMarkableIface
*iface
)
3179 iface
->mark
= imarkable_mark
;
3180 iface
->location_from_handle
= imarkable_location_from_handle
;
3181 iface
->unmark
= imarkable_unmark
;
3182 iface
->is_marker_set
= imarkable_is_marker_set
;
3183 iface
->delete_all_markers
= imarkable_delete_all_markers
;
3186 /* IAnjutaEditorConvert implementation */
3189 iconvert_to_upper (IAnjutaEditorConvert
* te
, IAnjutaIterable
*start_position
,
3190 IAnjutaIterable
*end_position
, GError
** ee
)
3193 start
= text_editor_cell_get_position (TEXT_EDITOR_CELL (start_position
));
3194 end
= text_editor_cell_get_position (TEXT_EDITOR_CELL (end_position
));
3195 scintilla_send_message (SCINTILLA (TEXT_EDITOR(te
)->scintilla
),
3196 SCI_SETSEL
, start
, end
);
3197 text_editor_command (TEXT_EDITOR(te
), ANE_UPRCASE
, 0, 0);
3201 iconvert_to_lower(IAnjutaEditorConvert
* te
, IAnjutaIterable
*start_position
,
3202 IAnjutaIterable
*end_position
, GError
** ee
)
3205 start
= text_editor_cell_get_position (TEXT_EDITOR_CELL (start_position
));
3206 end
= text_editor_cell_get_position (TEXT_EDITOR_CELL (end_position
));
3207 scintilla_send_message (SCINTILLA (TEXT_EDITOR(te
)->scintilla
),
3208 SCI_SETSEL
, start
, end
);
3209 text_editor_command (TEXT_EDITOR (te
), ANE_LWRCASE
, 0, 0);
3213 iconvert_iface_init (IAnjutaEditorConvertIface
*iface
)
3215 iface
->to_lower
= iconvert_to_lower
;
3216 iface
->to_upper
= iconvert_to_upper
;
3219 /* IAnjutaEditorLineMode implementation */
3221 static IAnjutaEditorLineModeType
3222 ilinemode_get (IAnjutaEditorLineMode
* te
, GError
** err
)
3225 IAnjutaEditorLineModeType retmode
;
3227 g_return_val_if_fail (IS_TEXT_EDITOR (te
), IANJUTA_EDITOR_LINE_MODE_LF
);
3229 eolmode
= scintilla_send_message (SCINTILLA (TEXT_EDITOR (te
)->scintilla
),
3230 SCI_GETEOLMODE
, 0, 0);
3234 retmode
= IANJUTA_EDITOR_LINE_MODE_CR
;
3237 retmode
= IANJUTA_EDITOR_LINE_MODE_CRLF
;
3240 retmode
= IANJUTA_EDITOR_LINE_MODE_LF
;
3243 retmode
= IANJUTA_EDITOR_LINE_MODE_LF
;
3244 g_warning ("Should not be here");
3250 ilinemode_set (IAnjutaEditorLineMode
* te
, IAnjutaEditorLineModeType mode
,
3253 g_return_if_fail (IS_TEXT_EDITOR (te
));
3257 case IANJUTA_EDITOR_LINE_MODE_LF
:
3258 text_editor_command(TEXT_EDITOR(te
), ANE_EOL_LF
, 0, 0);
3261 case IANJUTA_EDITOR_LINE_MODE_CR
:
3262 text_editor_command(TEXT_EDITOR(te
), ANE_EOL_CR
, 0, 0);
3265 case IANJUTA_EDITOR_LINE_MODE_CRLF
:
3266 text_editor_command(TEXT_EDITOR(te
), ANE_EOL_CRLF
, 0, 0);
3270 g_warning ("Should not reach here");
3276 ilinemode_convert (IAnjutaEditorLineMode
*te
, IAnjutaEditorLineModeType mode
,
3281 case IANJUTA_EDITOR_LINE_MODE_LF
:
3282 text_editor_command (TEXT_EDITOR (te
), ANE_EOL_CONVERT
,
3286 case IANJUTA_EDITOR_LINE_MODE_CR
:
3287 text_editor_command (TEXT_EDITOR (te
), ANE_EOL_CONVERT
,
3291 case IANJUTA_EDITOR_LINE_MODE_CRLF
:
3292 text_editor_command (TEXT_EDITOR (te
), ANE_EOL_CONVERT
,
3297 g_warning ("Should not reach here");
3303 ilinemode_fix (IAnjutaEditorLineMode
* te
, GError
** err
)
3305 IAnjutaEditorLineModeType mode
= ilinemode_get (te
, NULL
);
3306 ilinemode_convert (te
, mode
, NULL
);
3310 ilinemode_iface_init (IAnjutaEditorLineModeIface
*iface
)
3312 iface
->set
= ilinemode_set
;
3313 iface
->get
= ilinemode_get
;
3314 iface
->convert
= ilinemode_convert
;
3315 iface
->fix
= ilinemode_fix
;
3319 itip_show (IAnjutaEditorTip
*itip
, GList
* tips
,
3320 IAnjutaIterable
*position
, GError
**err
)
3325 TextEditor
*te
= TEXT_EDITOR (itip
);
3326 TextEditorCell
*cell
= TEXT_EDITOR_CELL (position
);
3329 g_return_if_fail (IS_TEXT_EDITOR (te
));
3330 g_return_if_fail (tips
!= NULL
);
3331 tips_count
= g_list_length (tips
);
3332 g_return_if_fail (tips_count
> 0);
3334 DEBUG_PRINT ("Number of calltips found %d\n", tips_count
);
3336 calltip
= g_string_sized_new (256);
3340 if (calltip
->len
> 0)
3341 g_string_append_c (calltip
, '\n');
3342 g_string_append (calltip
, (gchar
*) tip
->data
);
3343 tip
= g_list_next (tip
);
3346 /* It is not possible to display the calltip above, as the position is defined
3347 * in characters. We cannot be sure that there is enough characters in
3349 calltip_pos
= text_editor_cell_get_position (cell
);
3351 scintilla_send_message (SCINTILLA (te
->scintilla
),
3354 (uptr_t
) calltip
->str
);
3355 g_string_free (calltip
, TRUE
);
3359 itip_cancel (IAnjutaEditorTip
*itip
, GError
**err
)
3361 TextEditor
*te
= TEXT_EDITOR (itip
);
3362 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_CALLTIPCANCEL
, 0, 0);
3366 itip_visible (IAnjutaEditorTip
* itip
, GError
**err
)
3368 TextEditor
*te
= TEXT_EDITOR (itip
);
3369 return scintilla_send_message (SCINTILLA (te
->scintilla
),
3370 SCI_CALLTIPACTIVE
, 0, 0);
3374 itip_iface_init (IAnjutaEditorTipIface
*iface
)
3376 iface
->show
= itip_show
;
3377 iface
->cancel
= itip_cancel
;
3378 iface
->visible
= itip_visible
;
3381 /* IAnjutaEditorAssist implementation */
3383 iassist_add(IAnjutaEditorAssist
* iassist
, IAnjutaProvider
* provider
, GError
** err
)
3385 TextEditor
*te
= TEXT_EDITOR (iassist
);
3386 te
->provider
= g_list_prepend (te
->provider
, provider
);
3390 iassist_remove(IAnjutaEditorAssist
* iassist
, IAnjutaProvider
* provider
, GError
** err
)
3392 TextEditor
*te
= TEXT_EDITOR (iassist
);
3393 te
->provider
= g_list_remove (te
->provider
, provider
);
3397 iassist_invoke(IAnjutaEditorAssist
* iassist
, IAnjutaProvider
* provider
, GError
** err
)
3399 TextEditor
*te
= TEXT_EDITOR (iassist
);
3401 text_editor_suggest_completion (te
);
3405 iassist_proposals(IAnjutaEditorAssist
* iassist
, IAnjutaProvider
* provider
,
3406 GList
* proposals
, const gchar
*pre_word
, gboolean finished
, GError
** err
)
3408 TextEditor
*te
= TEXT_EDITOR (iassist
);
3412 /* Hide if the only suggetions is exactly the typed word */
3413 if (pre_word
&& proposals
&& g_list_length (proposals
) == 1)
3415 IAnjutaEditorAssistProposal
* prop
= proposals
->data
;
3416 if (g_str_equal (pre_word
, prop
->label
))
3420 if (proposals
== NULL
)
3422 te
->completion_count
= 0;
3423 g_string_truncate (te
->completion_string
, 0);
3425 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_AUTOCCANCEL
,
3430 if (te
->completion_finished
)
3432 te
->completion_count
= 0;
3433 g_string_truncate (te
->completion_string
, 0);
3435 te
->completion_finished
= finished
;
3437 for (node
= proposals
; node
!= NULL
; node
= g_list_next (node
))
3439 IAnjutaEditorAssistProposal
* prop
= node
->data
;
3441 /* Give up if there is too much completion */
3442 if (te
->completion_count
>= SCINTILLA_MAX_COMPLETION
) return;
3445 if (te
->completion_string
->len
> 0)
3446 g_string_append_c (te
->completion_string
, ' ');
3447 g_string_append(te
->completion_string
, prop
->label
);
3448 te
->completion
[te
->completion_count
].provider
= provider
;
3449 te
->completion
[te
->completion_count
].data
= prop
->data
;
3450 te
->completion_count
++;
3454 scintilla_send_message (SCINTILLA (te
->scintilla
),
3455 SCI_AUTOCSETAUTOHIDE
, 1, 0);
3456 scintilla_send_message (SCINTILLA (te
->scintilla
),
3457 SCI_AUTOCSETDROPRESTOFWORD
, 1, 0);
3458 scintilla_send_message (SCINTILLA (te
->scintilla
),
3459 SCI_AUTOCSETCANCELATSTART
, 0, 0);
3460 scintilla_send_message (SCINTILLA (te
->scintilla
),
3461 SCI_AUTOCSETCHOOSESINGLE
, 0, 0);
3463 length
= text_editor_get_current_position (te
);
3464 length
-= text_editor_cell_get_position (TEXT_EDITOR_CELL (ianjuta_provider_get_start_iter (provider
, NULL
)));
3466 scintilla_send_message (SCINTILLA (te
->scintilla
),
3467 SCI_AUTOCSHOW
, length
,
3468 (uptr_t
) te
->completion_string
->str
);
3472 iassist_iface_init(IAnjutaEditorAssistIface
* iface
)
3474 iface
->add
= iassist_add
;
3475 iface
->remove
= iassist_remove
;
3476 iface
->invoke
= iassist_invoke
;
3477 iface
->proposals
= iassist_proposals
;
3480 /* IAnutaEditorFolds implementation */
3483 ifolds_open_all(IAnjutaEditorFolds
* view
, GError
**e
)
3485 text_editor_command(TEXT_EDITOR(view
), ANE_OPEN_FOLDALL
, 0, 0);
3489 ifolds_close_all(IAnjutaEditorFolds
* view
, GError
**e
)
3491 text_editor_command(TEXT_EDITOR(view
), ANE_CLOSE_FOLDALL
, 0, 0);
3495 ifolds_toggle_current(IAnjutaEditorFolds
* view
, GError
**e
)
3497 text_editor_command(TEXT_EDITOR(view
), ANE_TOGGLE_FOLD
, 0, 0);
3501 ifolds_iface_init(IAnjutaEditorFoldsIface
* iface
)
3503 iface
->open_all
= ifolds_open_all
;
3504 iface
->close_all
= ifolds_close_all
;
3505 iface
->toggle_current
= ifolds_toggle_current
;
3508 /* IAnjutaEditorView implementation */
3510 iview_create (IAnjutaEditorView
*view
, GError
**err
)
3512 g_return_if_fail (IS_TEXT_EDITOR (view
));
3513 text_editor_add_view (TEXT_EDITOR (view
));
3517 iview_remove_current (IAnjutaEditorView
*view
, GError
**err
)
3519 g_return_if_fail (IS_TEXT_EDITOR (view
));
3520 text_editor_remove_view (TEXT_EDITOR (view
));
3524 iview_get_count (IAnjutaEditorView
*view
, GError
**err
)
3526 g_return_val_if_fail (IS_TEXT_EDITOR (view
), -1);
3527 return g_list_length (TEXT_EDITOR (view
)->views
);
3531 iview_iface_init (IAnjutaEditorViewIface
*iface
)
3533 iface
->create
= iview_create
;
3534 iface
->remove_current
= iview_remove_current
;
3535 iface
->get_count
= iview_get_count
;
3539 iindicable_set (IAnjutaIndicable
*te
, IAnjutaIterable
*begin_location
,
3540 IAnjutaIterable
*end_location
,
3541 IAnjutaIndicableIndicator indicator
, GError
**err
)
3543 gint begin
= text_editor_cell_get_position (TEXT_EDITOR_CELL (begin_location
));
3544 gint end
= text_editor_cell_get_position (TEXT_EDITOR_CELL (end_location
));
3547 case IANJUTA_INDICABLE_NONE
:
3548 text_editor_clear_indicator (TEXT_EDITOR (te
), begin
, end
);
3550 case IANJUTA_INDICABLE_IMPORTANT
:
3551 text_editor_set_indicator (TEXT_EDITOR (te
), begin
, end
, 0);
3553 case IANJUTA_INDICABLE_WARNING
:
3554 text_editor_set_indicator (TEXT_EDITOR (te
), begin
, end
, 1);
3556 case IANJUTA_INDICABLE_CRITICAL
:
3557 text_editor_set_indicator (TEXT_EDITOR (te
), begin
, end
, 2);
3560 g_warning ("Unsupported indicator %d", indicator
);
3561 text_editor_clear_indicator (TEXT_EDITOR (te
), begin
, end
);
3567 iindicable_clear (IAnjutaIndicable
*te
, GError
**err
)
3569 text_editor_clear_all_indicator (TEXT_EDITOR (te
));
3573 iindicable_iface_init (IAnjutaIndicableIface
*iface
)
3575 iface
->set
= iindicable_set
;
3576 iface
->clear
= iindicable_clear
;
3580 iprint_print(IAnjutaPrint
* print
, GError
** e
)
3582 TextEditor
* te
= TEXT_EDITOR(print
);
3583 anjuta_print(FALSE
, te
->settings
, te
);
3587 iprint_preview(IAnjutaPrint
* print
, GError
** e
)
3589 TextEditor
* te
= TEXT_EDITOR(print
);
3590 anjuta_print(TRUE
, te
->settings
, te
);
3594 iprint_iface_init(IAnjutaPrintIface
* iface
)
3596 iface
->print
= iprint_print
;
3597 iface
->print_preview
= iprint_preview
;
3601 icomment_block(IAnjutaEditorComment
* comment
, GError
** e
)
3603 TextEditor
* te
= TEXT_EDITOR(comment
);
3604 aneditor_command (te
->editor_id
, ANE_BLOCKCOMMENT
, 0, 0);
3608 icomment_stream(IAnjutaEditorComment
* comment
, GError
** e
)
3610 TextEditor
* te
= TEXT_EDITOR(comment
);
3611 aneditor_command (te
->editor_id
, ANE_STREAMCOMMENT
, 0, 0);
3615 icomment_box(IAnjutaEditorComment
* comment
, GError
** e
)
3617 TextEditor
* te
= TEXT_EDITOR(comment
);
3618 aneditor_command (te
->editor_id
, ANE_BOXCOMMENT
, 0, 0);
3622 icomment_iface_init(IAnjutaEditorCommentIface
* iface
)
3624 iface
->block
= icomment_block
;
3625 iface
->box
= icomment_box
;
3626 iface
->stream
= icomment_stream
;
3629 #define MAX_ZOOM_FACTOR 8
3630 #define MIN_ZOOM_FACTOR -8
3633 izoom_in(IAnjutaEditorZoom
* zoom
, GError
** e
)
3635 TextEditor
* te
= TEXT_EDITOR(zoom
);
3636 gint zoom_factor
= g_settings_get_int (te
->docman_settings
,
3637 TEXT_ZOOM_FACTOR
) + 1;
3639 if (zoom_factor
> MAX_ZOOM_FACTOR
)
3640 zoom_factor
= MAX_ZOOM_FACTOR
;
3641 else if (zoom_factor
< MIN_ZOOM_FACTOR
)
3642 zoom_factor
= MIN_ZOOM_FACTOR
;
3644 g_settings_set_int (te
->docman_settings
, TEXT_ZOOM_FACTOR
, zoom_factor
);
3648 izoom_out(IAnjutaEditorZoom
* zoom
, GError
** e
)
3650 TextEditor
* te
= TEXT_EDITOR(zoom
);
3651 gint zoom_factor
= g_settings_get_int (te
->docman_settings
,
3652 TEXT_ZOOM_FACTOR
) - 1;
3654 if (zoom_factor
> MAX_ZOOM_FACTOR
)
3655 zoom_factor
= MAX_ZOOM_FACTOR
;
3656 else if (zoom_factor
< MIN_ZOOM_FACTOR
)
3657 zoom_factor
= MIN_ZOOM_FACTOR
;
3659 g_settings_set_int (te
->docman_settings
, TEXT_ZOOM_FACTOR
, zoom_factor
);
3663 izoom_iface_init(IAnjutaEditorZoomIface
* iface
)
3665 iface
->in
= izoom_in
;
3666 iface
->out
= izoom_out
;
3670 igoto_start_block(IAnjutaEditorGoto
* editor
, GError
** e
)
3672 TextEditor
* te
= TEXT_EDITOR(editor
);
3673 text_editor_goto_block_start(te
);
3677 igoto_end_block(IAnjutaEditorGoto
* editor
, GError
** e
)
3679 TextEditor
* te
= TEXT_EDITOR(editor
);
3680 text_editor_goto_block_end(te
);
3684 igoto_matching_brace(IAnjutaEditorGoto
* editor
, GError
** e
)
3686 TextEditor
* te
= TEXT_EDITOR(editor
);
3687 text_editor_command (te
, ANE_MATCHBRACE
, 0, 0);
3691 igoto_iface_init(IAnjutaEditorGotoIface
* iface
)
3693 iface
->start_block
= igoto_start_block
;
3694 iface
->end_block
= igoto_end_block
;
3695 iface
->matching_brace
= igoto_matching_brace
;
3699 ilanguage_get_supported_languages (IAnjutaEditorLanguage
*ilanguage
,
3702 if (supported_languages
== NULL
)
3706 gchar
*menu_entries
;
3708 supported_languages_name
=
3709 g_hash_table_new_full (g_str_hash
, g_str_equal
,
3711 supported_languages_ext
=
3712 g_hash_table_new_full (g_str_hash
, g_str_equal
,
3715 supported_languages_by_lexer
=
3716 g_hash_table_new_full (g_str_hash
, g_str_equal
,
3719 menu_entries
= sci_prop_get (text_editor_get_props (), "menu.language");
3720 g_return_val_if_fail (menu_entries
!= NULL
, NULL
);
3722 strv
= g_strsplit (menu_entries
, "|", -1);
3727 gchar
*possible_file
;
3729 gchar
*name
, *extension
;
3732 lang
= g_string_new ("");
3738 extension
= *token
++;
3755 g_string_append_c (lang
, g_ascii_tolower (*iter
));
3760 /* HACK: Convert the weird c++ name to cpp */
3761 if (strcmp (lang
->str
, "c / c++") == 0)
3763 g_string_assign (lang
, "cpp");
3766 /* Updated mapping hash tables */
3767 g_hash_table_insert (supported_languages_name
, lang
->str
,
3769 g_hash_table_insert (supported_languages_ext
, lang
->str
,
3770 g_strconcat ("file.", extension
, NULL
));
3771 /* Map lexer to language */
3772 possible_file
= g_strconcat ("file.", extension
, NULL
);
3773 lexer
= sci_prop_get_new_expand (TEXT_EDITOR (ilanguage
)->props_base
,
3774 "lexer.", possible_file
);
3775 g_free (possible_file
);
3778 /* We only map the first (which is hopefully the true) language */
3779 if (!g_hash_table_lookup (supported_languages_by_lexer
, lexer
))
3781 /* DEBUG_PRINT ("Mapping (lexer)%s to (language)%s", lexer, lang->str); */
3782 g_hash_table_insert (supported_languages_by_lexer
,
3784 /* lexer is taken in the hash, so no free */
3792 supported_languages
= g_list_prepend (supported_languages
,
3794 g_string_free (lang
, FALSE
);
3798 return supported_languages
;
3802 ilanguage_get_language_name (IAnjutaEditorLanguage
*ilanguage
,
3803 const gchar
*language
, GError
**err
)
3805 if (!supported_languages_name
)
3806 ilanguage_get_supported_languages (ilanguage
, NULL
);
3808 return g_hash_table_lookup (supported_languages_name
, language
);
3812 ilanguage_set_language (IAnjutaEditorLanguage
*ilanguage
,
3813 const gchar
*language
, GError
**err
)
3815 if (!supported_languages_ext
)
3816 ilanguage_get_supported_languages (ilanguage
, NULL
);
3819 text_editor_set_hilite_type (TEXT_EDITOR (ilanguage
),
3820 g_hash_table_lookup (supported_languages_ext
,
3822 else /* Autodetect */
3823 text_editor_set_hilite_type (TEXT_EDITOR (ilanguage
), NULL
);
3825 text_editor_hilite (TEXT_EDITOR (ilanguage
), FALSE
);
3829 ilanguage_get_language (IAnjutaEditorLanguage
*ilanguage
, GError
**err
)
3831 const gchar
*language
= NULL
;
3832 const gchar
*filename
= NULL
;
3833 TextEditor
*te
= TEXT_EDITOR (ilanguage
);
3835 if (te
->force_hilite
)
3836 filename
= te
->force_hilite
;
3837 else if (te
->filename
)
3838 filename
= te
->filename
;
3842 gchar
*lexer
= NULL
;
3843 lexer
= sci_prop_get_new_expand (te
->props_base
,
3844 "lexer.", filename
);
3846 /* No lexer, no language */
3849 if (!supported_languages_by_lexer
)
3850 ilanguage_get_supported_languages (ilanguage
, NULL
);
3852 language
= g_hash_table_lookup (supported_languages_by_lexer
, lexer
);
3853 /* DEBUG_PRINT ("Found (language)%s for (lexer)%s", language, lexer); */
3861 ilanguage_iface_init (IAnjutaEditorLanguageIface
*iface
)
3863 iface
->get_supported_languages
= ilanguage_get_supported_languages
;
3864 iface
->get_language_name
= ilanguage_get_language_name
;
3865 iface
->get_language
= ilanguage_get_language
;
3866 iface
->set_language
= ilanguage_set_language
;
3870 isearch_forward (IAnjutaEditorSearch
* isearch
,
3871 const gchar
* search
,
3872 gboolean case_sensitive
,
3873 IAnjutaEditorCell
* istart
,
3874 IAnjutaEditorCell
* iend
,
3875 IAnjutaEditorCell
** iresult_start
,
3876 IAnjutaEditorCell
** iresult_end
,
3879 TextEditor
*te
= TEXT_EDITOR (isearch
);
3880 gint start
= text_editor_cell_get_position (TEXT_EDITOR_CELL (istart
));
3881 gint end
= text_editor_cell_get_position (TEXT_EDITOR_CELL (iend
));
3888 flags
= SCFIND_MATCHCASE
;
3891 struct Sci_TextToFind to_find
;
3893 to_find
.chrg
.cpMin
= start
;
3894 to_find
.chrg
.cpMax
= end
;
3896 to_find
.lpstrText
= (gchar
*) search
;
3898 retval
= scintilla_send_message (SCINTILLA (te
->scintilla
),
3899 SCI_FINDTEXT
, flags
, (long) &to_find
);
3904 *iresult_start
= IANJUTA_EDITOR_CELL (text_editor_cell_new (te
, to_find
.chrgText
.cpMin
));
3905 *iresult_end
= IANJUTA_EDITOR_CELL (text_editor_cell_new (te
, to_find
.chrgText
.cpMax
));
3911 isearch_backward (IAnjutaEditorSearch
* isearch
,
3912 const gchar
* search
,
3913 gboolean case_sensitive
,
3914 IAnjutaEditorCell
* istart
,
3915 IAnjutaEditorCell
* iend
,
3916 IAnjutaEditorCell
** iresult_start
,
3917 IAnjutaEditorCell
** iresult_end
,
3920 TextEditor
*te
= TEXT_EDITOR (isearch
);
3921 gint end
= text_editor_cell_get_position (TEXT_EDITOR_CELL (iend
));
3922 gint start
= text_editor_cell_get_position (TEXT_EDITOR_CELL (istart
));
3929 flags
= SCFIND_MATCHCASE
;
3932 struct Sci_TextToFind to_find
;
3934 to_find
.chrg
.cpMin
= start
;
3935 to_find
.chrg
.cpMax
= end
;
3937 to_find
.lpstrText
= (gchar
*) search
;
3939 retval
= scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_FINDTEXT
, flags
, (long) &to_find
);
3944 *iresult_start
= IANJUTA_EDITOR_CELL (text_editor_cell_new (te
, to_find
.chrgText
.cpMin
));
3945 *iresult_end
= IANJUTA_EDITOR_CELL (text_editor_cell_new (te
, to_find
.chrgText
.cpMax
));
3951 isearch_iface_init(IAnjutaEditorSearchIface
* iface
)
3953 iface
->forward
= isearch_forward
;
3954 iface
->backward
= isearch_backward
;
3958 ihover_display (IAnjutaEditorHover
*ihover
, IAnjutaIterable
*pos
,
3959 const gchar
*info
, GError
**e
)
3961 TextEditor
*te
= TEXT_EDITOR (ihover
);
3962 gint position
= text_editor_cell_get_position (TEXT_EDITOR_CELL (pos
));
3963 g_return_if_fail (position
>= 0);
3964 g_return_if_fail (info
!= NULL
);
3965 text_editor_show_hover_tip (te
, position
, info
);
3969 ihover_iface_init(IAnjutaEditorHoverIface
* iface
)
3971 iface
->display
= ihover_display
;
3974 ANJUTA_TYPE_BEGIN(TextEditor
, text_editor
, GTK_TYPE_VBOX
);
3975 ANJUTA_TYPE_ADD_INTERFACE(ifile
, IANJUTA_TYPE_FILE
);
3976 ANJUTA_TYPE_ADD_INTERFACE(isavable
, IANJUTA_TYPE_FILE_SAVABLE
);
3977 ANJUTA_TYPE_ADD_INTERFACE(idocument
, IANJUTA_TYPE_DOCUMENT
);
3978 ANJUTA_TYPE_ADD_INTERFACE(itext_editor
, IANJUTA_TYPE_EDITOR
);
3979 ANJUTA_TYPE_ADD_INTERFACE(ilinemode
, IANJUTA_TYPE_EDITOR_LINE_MODE
);
3980 ANJUTA_TYPE_ADD_INTERFACE(iselection
, IANJUTA_TYPE_EDITOR_SELECTION
);
3981 ANJUTA_TYPE_ADD_INTERFACE(iconvert
, IANJUTA_TYPE_EDITOR_CONVERT
);
3982 ANJUTA_TYPE_ADD_INTERFACE(iassist
, IANJUTA_TYPE_EDITOR_ASSIST
);
3983 ANJUTA_TYPE_ADD_INTERFACE(itip
, IANJUTA_TYPE_EDITOR_TIP
);
3984 ANJUTA_TYPE_ADD_INTERFACE(ilanguage
, IANJUTA_TYPE_EDITOR_LANGUAGE
);
3985 ANJUTA_TYPE_ADD_INTERFACE(iview
, IANJUTA_TYPE_EDITOR_VIEW
);
3986 ANJUTA_TYPE_ADD_INTERFACE(ifolds
, IANJUTA_TYPE_EDITOR_FOLDS
);
3987 ANJUTA_TYPE_ADD_INTERFACE(imarkable
, IANJUTA_TYPE_MARKABLE
);
3988 ANJUTA_TYPE_ADD_INTERFACE(iindicable
, IANJUTA_TYPE_INDICABLE
);
3989 ANJUTA_TYPE_ADD_INTERFACE(iprint
, IANJUTA_TYPE_PRINT
);
3990 ANJUTA_TYPE_ADD_INTERFACE(icomment
, IANJUTA_TYPE_EDITOR_COMMENT
);
3991 ANJUTA_TYPE_ADD_INTERFACE(izoom
, IANJUTA_TYPE_EDITOR_ZOOM
);
3992 ANJUTA_TYPE_ADD_INTERFACE(igoto
, IANJUTA_TYPE_EDITOR_GOTO
);
3993 ANJUTA_TYPE_ADD_INTERFACE(isearch
, IANJUTA_TYPE_EDITOR_SEARCH
);
3994 ANJUTA_TYPE_ADD_INTERFACE(ihover
, IANJUTA_TYPE_EDITOR_HOVER
);