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
26 #include <libanjuta/resources.h>
27 #include <libanjuta/anjuta-utils.h>
28 #include <libanjuta/anjuta-debug.h>
30 #include "text_editor.h"
31 #include "text_editor_cbs.h"
32 #include "text-editor-iterable.h"
37 #include "Scintilla.h"
39 #include "ScintillaWidget.h"
42 on_text_editor_scintilla_focus_in (GtkWidget
* scintilla
, GdkEvent
*event
,
50 if (aneditor_get_widget (GPOINTER_TO_INT (node
->data
)) == scintilla
)
52 DEBUG_PRINT ("Switching editor view ...");
53 te
->editor_id
= GPOINTER_TO_INT (node
->data
);
54 te
->scintilla
= aneditor_get_widget (te
->editor_id
);
57 node
= g_list_next (node
);
63 on_text_editor_text_buttonpress_event (GtkWidget
* widget
,
64 GdkEventButton
* event
,
67 TextEditor
*te
= user_data
;
68 gtk_widget_grab_focus (GTK_WIDGET (te
->scintilla
));
73 on_text_editor_text_event (GtkWidget
* widget
,
74 GdkEvent
* event
, gpointer user_data
)
76 TextEditor
*te
= TEXT_EDITOR (user_data
);
77 GdkEventButton
*bevent
;
79 if (event
->type
!= GDK_BUTTON_PRESS
)
81 if (((GdkEventButton
*) event
)->button
!= 3)
83 if (!text_editor_has_selection (te
))
85 /* Move cursor to set breakpoints at correct line (#530689) */
87 gint x
= (gint
)((GdkEventButton
*) event
)->x
;
88 gint y
= (gint
)((GdkEventButton
*) event
)->y
;
90 pos
= scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_POSITIONFROMPOINT
, x
, y
);
93 scintilla_send_message (SCINTILLA (te
->scintilla
), SCI_GOTOPOS
, pos
, 0);
96 bevent
= (GdkEventButton
*) event
;
98 gtk_menu_popup (GTK_MENU (te
->popup_menu
),
99 NULL
, NULL
, NULL
, NULL
,
100 bevent
->button
, bevent
->time
);
105 scintilla_uri_dropped (TextEditor
*te
, const char *uri
)
108 GtkSelectionData tmp
;
110 tmp
.data
= (guchar
*) uri
;
112 parent
= gtk_widget_get_toplevel (GTK_WIDGET (te
));
114 g_signal_emit_by_name (G_OBJECT (parent
), "drag_data_received",
115 NULL
, 0, 0, &tmp
, 0, 0);
119 gboolean timerclick
= FALSE
;
122 click_timeout (TextEditor
*te
)
124 gint line
= GPOINTER_TO_INT (g_object_get_data (G_OBJECT (te
),
127 /* If not second clic after timeout : Single Click */
131 /* Emit (single) clicked signal */
132 g_signal_emit_by_name (G_OBJECT (te
), "marker_clicked", FALSE
, line
);
138 on_text_editor_scintilla_notify (GtkWidget
* sci
, gint wParam
, gpointer lParam
,
142 struct SCNotification
*nt
;
143 gint line
, position
, autoc_sel
;
146 if (te
->freeze_count
!= 0)
149 switch (nt
->nmhdr
.code
)
152 scintilla_uri_dropped(te
, nt
->text
);
154 case SCN_SAVEPOINTREACHED
:
155 g_signal_emit_by_name(G_OBJECT (te
), "save_point", TRUE
);
157 case SCN_SAVEPOINTLEFT
:
158 g_signal_emit_by_name(G_OBJECT (te
), "save_point", FALSE
);
160 // anjuta_update_title ();
161 // update_main_menubar ();
162 text_editor_update_controls (te
);
165 te
->current_line
= text_editor_get_current_lineno (te
);
166 g_signal_emit_by_name(G_OBJECT (te
), "update_ui");
171 position
= text_editor_get_current_position (te
) - 1;
172 TextEditorCell
*position_iter
= text_editor_cell_new (te
, position
);
173 te
->current_line
= text_editor_get_current_lineno (te
);
174 g_signal_emit_by_name(G_OBJECT (te
), "char-added", position_iter
,
176 g_object_unref (position_iter
);
179 case SCN_AUTOCSELECTION
:
180 case SCN_USERLISTSELECTION
:
181 autoc_sel
= (gint
) scintilla_send_message (SCINTILLA (te
->scintilla
),
184 scintilla_send_message (SCINTILLA (te
->scintilla
),
185 SCI_AUTOCCANCEL
, 0, 0);
186 g_signal_emit_by_name (te
, "assist-chosen", autoc_sel
);
189 if (nt
->modificationType
& (SC_MOD_INSERTTEXT
| SC_MOD_DELETETEXT
))
191 TextEditorCell
*position_iter
=
192 text_editor_cell_new (te
, nt
->position
);
193 gboolean added
= nt
->modificationType
& SC_MOD_INSERTTEXT
;
194 g_signal_emit_by_name (G_OBJECT (te
), "changed", position_iter
,
195 added
, nt
->length
, nt
->linesAdded
,
197 g_object_unref (position_iter
);
200 case SCN_MARGINCLICK
:
201 line
= text_editor_get_line_from_position (te
, nt
->position
);
202 if (nt
->margin
== 1) /* Bookmarks and Breakpoints margin */
204 /* if second click before timeout : Double click */
208 text_editor_goto_line (te
, line
, -1, TRUE
);
209 aneditor_command (te
->editor_id
, ANE_BOOKMARK_TOGGLE
, 0, 0);
210 /* Emit (double) clicked signal */
211 g_signal_emit_by_name (G_OBJECT (te
), "marker_clicked",
217 g_object_set_data (G_OBJECT (te
), "marker_line",
218 GINT_TO_POINTER (line
));
219 /* Timeout after 400ms */
220 /* If 2 clicks before the timeout ==> Single Click */
221 g_timeout_add (400, (void*) click_timeout
, te
);
227 TextEditorCell
* cell
= nt
->position
< 0 ? NULL
: text_editor_cell_new (te
, nt
->position
);
228 g_signal_emit_by_name (te
, "hover-over", cell
);
229 if (cell
) g_object_unref (cell
);
235 TextEditorCell
* cell
= nt
->position
< 0 ? NULL
: text_editor_cell_new (te
, nt
->position
);
237 text_editor_hide_hover_tip (te
);
238 g_signal_emit_by_name (te
, "hover-leave", cell
);
239 if (cell
) g_object_unref (cell
);
243 /* case SCEN_SETFOCUS:
245 case SCN_STYLENEEDED:
246 case SCN_DOUBLECLICK:
256 on_text_editor_scintilla_size_allocate (GtkWidget
* widget
,
257 GtkAllocation
* allocation
,
262 g_return_if_fail (te
!= NULL
);
264 if (te
->first_time_expose
== FALSE
)
267 te
->first_time_expose
= FALSE
;
268 text_editor_goto_line (te
, te
->current_line
, FALSE
, FALSE
);