3 * Copyright (C) 2000 Kh. Naba Kumar Singh
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <gdk/gdkkeysyms.h>
28 #include <libanjuta/resources.h>
29 #include <libanjuta/anjuta-utils.h>
30 #include <libanjuta/anjuta-debug.h>
31 #include <libanjuta/interfaces/ianjuta-file-loader.h>
33 #include "text_editor.h"
34 #include "text_editor_cbs.h"
35 #include "text-editor-iterable.h"
40 #include "Scintilla.h"
42 #include "ScintillaWidget.h"
45 on_text_editor_scintilla_focus_in (GtkWidget
* scintilla
, GdkEvent
*event
,
53 if (aneditor_get_widget (GPOINTER_TO_INT (node
->data
)) == scintilla
)
55 DEBUG_PRINT ("%s", "Switching editor view ...");
56 te
->editor_id
= GPOINTER_TO_INT (node
->data
);
57 te
->scintilla
= aneditor_get_widget (te
->editor_id
);
60 node
= g_list_next (node
);
66 on_text_editor_text_buttonpress_event (GtkWidget
* widget
,
67 GdkEventButton
* event
,
70 TextEditor
*te
= user_data
;
71 gtk_widget_grab_focus (GTK_WIDGET (te
->scintilla
));
76 on_text_editor_text_keyrelease_event (GtkWidget
* widget
,
80 if (event
->keyval
== GDK_KEY_BackSpace
)
82 TextEditor
*te
= user_data
;
83 g_signal_emit_by_name(G_OBJECT(te
), "backspace");
89 on_text_editor_text_event (GtkWidget
* widget
,
90 GdkEvent
* event
, gpointer user_data
)
92 TextEditor
*te
= TEXT_EDITOR (user_data
);
93 GdkEventButton
*bevent
;
95 if (event
->type
!= GDK_BUTTON_PRESS
)
97 if (((GdkEventButton
*) event
)->button
!= 3)
99 if (!text_editor_has_selection (te
))
101 /* Move cursor to set breakpoints at correct line (#530689) */
103 gint x
= (gint
)((GdkEventButton
*) event
)->x
;
104 gint y
= (gint
)((GdkEventButton
*) event
)->y
;
106 pos
= scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_POSITIONFROMPOINT
, x
, y
);
109 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GOTOPOS
, pos
, 0);
112 bevent
= (GdkEventButton
*) event
;
114 gtk_menu_popup (GTK_MENU (te
->popup_menu
),
115 NULL
, NULL
, NULL
, NULL
,
116 bevent
->button
, bevent
->time
);
121 scintilla_uri_dropped (TextEditor
*te
, const char *uris
)
123 IAnjutaFileLoader
*loader
;
125 loader
= anjuta_shell_get_interface(te
->shell
, IAnjutaFileLoader
, NULL
);
131 /* The uri list is separated by DOS end of line */
132 list
= g_strsplit_set (uris
, "\r\n", -1);
133 for (uri
= list
; *uri
!= NULL
; uri
++)
139 file
= g_file_new_for_uri (*uri
);
140 ianjuta_file_loader_load(loader
, file
, FALSE
, NULL
);
141 g_object_unref (file
);
150 gboolean timerclick
= FALSE
;
153 click_timeout (TextEditor
*te
)
155 gint line
= GPOINTER_TO_INT (g_object_get_data (G_OBJECT (te
),
158 /* If not second clic after timeout : Single Click */
162 /* Emit (single) clicked signal */
163 g_signal_emit_by_name (G_OBJECT (te
), "marker_clicked", FALSE
, line
);
169 on_text_editor_scintilla_notify (GtkWidget
* sci
, gint wParam
, gpointer lParam
,
173 struct SCNotification
*nt
;
177 if (te
->freeze_count
!= 0)
180 switch (nt
->nmhdr
.code
)
183 scintilla_uri_dropped(te
, nt
->text
);
185 case SCN_SAVEPOINTREACHED
:
186 g_signal_emit_by_name(G_OBJECT (te
), "update_save_ui");
188 case SCN_SAVEPOINTLEFT
:
189 g_signal_emit_by_name(G_OBJECT (te
), "update_save_ui");
191 // anjuta_update_title ();
192 // update_main_menubar ();
193 text_editor_update_controls (te
);
196 te
->current_line
= text_editor_get_current_lineno (te
);
197 g_signal_emit_by_name(G_OBJECT (te
), "update_ui");
198 g_signal_emit_by_name(G_OBJECT (te
), "cursor-moved");
203 position
= text_editor_get_current_position (te
) - 1;
204 TextEditorCell
*position_iter
= text_editor_cell_new (te
, position
);
205 te
->current_line
= text_editor_get_current_lineno (te
);
206 g_signal_emit_by_name(G_OBJECT (te
), "char-added", position_iter
,
208 g_object_unref (position_iter
);
210 text_editor_suggest_completion (te
);
213 case SCN_AUTOCCANCELLED
:
214 text_editor_cancel_completion (te
);
216 case SCN_AUTOCCHARDELETED
:
217 text_editor_suggest_completion (te
);
219 case SCN_AUTOCSELECTION
:
220 case SCN_USERLISTSELECTION
:
221 text_editor_select_completion (te
);
224 if (nt
->modificationType
& (SC_MOD_INSERTTEXT
| SC_MOD_DELETETEXT
))
226 TextEditorCell
*position_iter
=
227 text_editor_cell_new (te
, nt
->position
);
228 gboolean added
= nt
->modificationType
& SC_MOD_INSERTTEXT
;
229 g_signal_emit_by_name (G_OBJECT (te
), "changed", position_iter
,
230 added
, nt
->length
, nt
->linesAdded
,
232 g_object_unref (position_iter
);
235 case SCN_MARGINCLICK
:
236 line
= text_editor_get_line_from_position (te
, nt
->position
);
237 if (nt
->margin
== 1) /* Bookmarks and Breakpoints margin */
239 /* if second click before timeout : Double click */
243 text_editor_goto_line (te
, line
, -1, TRUE
);
244 aneditor_command (te
->editor_id
, ANE_BOOKMARK_TOGGLE
, 0, 0);
245 /* Emit (double) clicked signal */
246 g_signal_emit_by_name (G_OBJECT (te
), "marker_clicked",
252 g_object_set_data (G_OBJECT (te
), "marker_line",
253 GINT_TO_POINTER (line
));
254 /* Timeout after 400ms */
255 /* If 2 clicks before the timeout ==> Single Click */
256 g_timeout_add (400, (void*) click_timeout
, te
);
262 TextEditorCell
* cell
= nt
->position
< 0 ? NULL
: text_editor_cell_new (te
, nt
->position
);
263 g_signal_emit_by_name (te
, "hover-over", cell
);
264 if (cell
) g_object_unref (cell
);
270 TextEditorCell
* cell
= nt
->position
< 0 ? NULL
: text_editor_cell_new (te
, nt
->position
);
272 text_editor_hide_hover_tip (te
);
273 g_signal_emit_by_name (te
, "hover-leave", cell
);
274 if (cell
) g_object_unref (cell
);
278 /* case SCEN_SETFOCUS:
280 case SCN_STYLENEEDED:
281 case SCN_DOUBLECLICK:
291 on_text_editor_scintilla_size_allocate (GtkWidget
* widget
,
292 GtkAllocation
* allocation
,
297 g_return_if_fail (te
!= NULL
);
299 if (te
->first_time_expose
== FALSE
)
302 te
->first_time_expose
= FALSE
;
303 text_editor_goto_line (te
, te
->current_line
, FALSE
, FALSE
);