Support individual files and folders in log output.
[anjuta-git-plugin.git] / plugins / editor / text_editor_cbs.c
blob4f5b1c3b0e86f4b8998b7ec97949cea416ed8a6d
1 /*
2 * text_editor_cbs.
3 * Copyright (C) 2000 Kh. Naba Kumar Singh
4 *
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.
9 *
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
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include <gnome.h>
24 #include <ctype.h>
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"
34 #define GTK
35 #undef PLAT_GTK
36 #define PLAT_GTK 1
37 #include "Scintilla.h"
38 #include "SciLexer.h"
39 #include "ScintillaWidget.h"
41 gboolean
42 on_text_editor_scintilla_focus_in (GtkWidget* scintilla, GdkEvent *event,
43 TextEditor *te)
45 GList *node;
47 node = te->views;
48 while (node)
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);
55 break;
57 node = g_list_next (node);
59 return FALSE;
62 gboolean
63 on_text_editor_text_buttonpress_event (GtkWidget * widget,
64 GdkEventButton * event,
65 gpointer user_data)
67 TextEditor *te = user_data;
68 gtk_widget_grab_focus (GTK_WIDGET (te->scintilla));
69 return FALSE;
72 gboolean
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)
80 return FALSE;
81 if (((GdkEventButton *) event)->button != 3)
82 return FALSE;
83 if (!text_editor_has_selection (te))
85 /* Move cursor to set breakpoints at correct line (#530689) */
86 glong pos;
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);
91 if (pos >= 0)
93 scintilla_send_message (SCINTILLA (te->scintilla), SCI_GOTOPOS, pos, 0);
96 bevent = (GdkEventButton *) event;
97 bevent->button = 1;
98 gtk_menu_popup (GTK_MENU (te->popup_menu),
99 NULL, NULL, NULL, NULL,
100 bevent->button, bevent->time);
101 return TRUE;
104 static void
105 scintilla_uri_dropped (TextEditor *te, const char *uri)
107 GtkWidget *parent;
108 GtkSelectionData tmp;
110 tmp.data = (guchar *) uri;
112 parent = gtk_widget_get_toplevel (GTK_WIDGET (te));
113 if (parent)
114 g_signal_emit_by_name (G_OBJECT (parent), "drag_data_received",
115 NULL, 0, 0, &tmp, 0, 0);
116 return;
119 gboolean timerclick = FALSE;
121 static gboolean
122 click_timeout (TextEditor *te)
124 gint line = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (te),
125 "marker_line"));
127 /* If not second clic after timeout : Single Click */
128 if (timerclick)
130 timerclick = FALSE;
131 /* Emit (single) clicked signal */
132 g_signal_emit_by_name (G_OBJECT (te), "marker_clicked", FALSE, line);
134 return FALSE;
137 void
138 on_text_editor_scintilla_notify (GtkWidget * sci, gint wParam, gpointer lParam,
139 gpointer data)
141 TextEditor *te;
142 struct SCNotification *nt;
143 gint line, position, autoc_sel;
145 te = data;
146 if (te->freeze_count != 0)
147 return;
148 nt = lParam;
149 switch (nt->nmhdr.code)
151 case SCN_URIDROPPED:
152 scintilla_uri_dropped(te, nt->text);
153 break;
154 case SCN_SAVEPOINTREACHED:
155 g_signal_emit_by_name(G_OBJECT (te), "save_point", TRUE);
156 break;
157 case SCN_SAVEPOINTLEFT:
158 g_signal_emit_by_name(G_OBJECT (te), "save_point", FALSE);
159 //FIXME:
160 // anjuta_update_title ();
161 // update_main_menubar ();
162 text_editor_update_controls (te);
163 return;
164 case SCN_UPDATEUI:
165 te->current_line = text_editor_get_current_lineno (te);
166 g_signal_emit_by_name(G_OBJECT (te), "update_ui");
167 return;
169 case SCN_CHARADDED:
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,
175 (gchar)nt->ch);
176 g_object_unref (position_iter);
178 return;
179 case SCN_AUTOCSELECTION:
180 case SCN_USERLISTSELECTION:
181 autoc_sel = (gint) scintilla_send_message (SCINTILLA (te->scintilla),
182 SCI_AUTOCGETCURRENT,
183 0, 0);
184 scintilla_send_message (SCINTILLA (te->scintilla),
185 SCI_AUTOCCANCEL, 0, 0);
186 g_signal_emit_by_name (te, "assist-chosen", autoc_sel);
187 return;
188 case SCN_MODIFIED:
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,
196 nt->text);
197 g_object_unref (position_iter);
199 return;
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 */
205 if (timerclick)
207 timerclick = FALSE;
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",
212 TRUE, line);
214 else
216 timerclick = TRUE;
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);
224 return;
225 case SCN_DWELLSTART:
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);
230 return;
233 case SCN_DWELLEND:
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);
240 return;
243 /* case SCEN_SETFOCUS:
244 case SCEN_KILLFOCUS:
245 case SCN_STYLENEEDED:
246 case SCN_DOUBLECLICK:
247 case SCN_MODIFIED:
248 case SCN_NEEDSHOWN:
250 default:
251 return;
255 void
256 on_text_editor_scintilla_size_allocate (GtkWidget * widget,
257 GtkAllocation * allocation,
258 gpointer data)
260 TextEditor *te;
261 te = data;
262 g_return_if_fail (te != NULL);
264 if (te->first_time_expose == FALSE)
265 return;
267 te->first_time_expose = FALSE;
268 text_editor_goto_line (te, te->current_line, FALSE, FALSE);