[anjuta] Feature for adding/removing a breakpoint on clicking besides the line number ( or the line marks gut
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] Feature for adding/removing a breakpoint on clicking besides the line number ( or the line marks gut
- Date: Sat, 1 May 2010 09:49:51 +0000 (UTC)
commit eaf79b4573f05e37c18e77e545c4350a872a9d61
Author: Saleem Ansari <tuxdna gmail com>
Date: Sat May 1 02:40:49 2010 +0530
Feature for adding/removing a breakpoint on clicking besides the line number ( or the line marks gutter in gtk sourceview ) - (bgo#616950).
* libanjuta/interfaces/libanjuta.idl:
(IAnjutaEditor::line-marks-gutter-clicked): Added signal.
* plugins/debug-manager/breakpoints.c:
(update_breakpoint): Split from function on_toggle_breakpoint_activate
into a new function.
(on_line_marks_gutter_clicked): New method to handle breakpoint
signals on line marks gutter.
(breakpoint_toggle_handler): This method exposes internal function
on_line_marks_gutter_clicked().
* plugins/debug-manager/breakpoints.h:
(breakpoint_toggle_handler): Prototype.
* plugins/debug-manager/plugin.c:
(value_added_current_editor): Connect callback for signal
'line-marks-gutter-clicked' on editor interface.
* plugins/sourceview/sourceview.c:
(sourceview_new): Connect callback for signal 'line-mark-activated'
on gtksourceview.
(on_line_mark_activated): Emit the corresponding signal on the
editor interface.
libanjuta/interfaces/libanjuta.idl | 13 ++++++-
plugins/debug-manager/breakpoints.c | 71 ++++++++++++++++++++++++++---------
plugins/debug-manager/breakpoints.h | 3 +
plugins/debug-manager/plugin.c | 24 +++++++++++-
plugins/sourceview/sourceview.c | 27 +++++++++++++
5 files changed, 118 insertions(+), 20 deletions(-)
---
diff --git a/libanjuta/interfaces/libanjuta.idl b/libanjuta/interfaces/libanjuta.idl
index f5a67ce..529025e 100644
--- a/libanjuta/interfaces/libanjuta.idl
+++ b/libanjuta/interfaces/libanjuta.idl
@@ -240,7 +240,8 @@ interface IAnjutaMarkable
BREAKPOINT_ENABLED,
PROGRAM_COUNTER
}
- /**
+
+ /**
* IAnjutaMarkable::marker-clicked:
* @obj: Self
* @double_click: whether the marker was double clicked
@@ -1293,6 +1294,16 @@ interface IAnjutaEditor
* number of line breaks in the added or removed text.
*/
void ::changed (GObject *position, gboolean added, gint length, gint lines, const gchar *text);
+
+ /**
+ * IAnjutaEditor::line-marks-gutter-clicked:
+ * @obj: Self
+ * @double_click: whether the line marks gutter was double clicked
+ * @location: location of the clicked marker
+ *
+ * The signal is emitted when the user clicks on a marker
+ */
+ void ::line_marks_gutter_clicked (gint location);
/**
* ianjuta_editor_get_tabsize:
diff --git a/plugins/debug-manager/breakpoints.c b/plugins/debug-manager/breakpoints.c
index 3203df6..79a48fc 100644
--- a/plugins/debug-manager/breakpoints.c
+++ b/plugins/debug-manager/breakpoints.c
@@ -1622,11 +1622,36 @@ on_jump_to_breakpoint_activate (GtkAction * action, BreakpointsDBase *bd)
}
}
+
+static void
+update_breakpoint(BreakpointsDBase *bd, IAnjutaEditor *te, gchar *uri, guint line_number){
+ /* Find corresponding breakpoint
+ * Try to find right mark (it could have moved) first */
+ BreakpointItem *bi;
+ bi = breakpoints_dbase_find_breakpoint_from_mark (bd, te, line_number);
+ DEBUG_PRINT("breakpoints db %p, editor %p, uri %s, line_number %p, BreakpointItem %p", bd, te, uri, line_number, bi);
+ if (bi == NULL)
+ {
+ bi = breakpoints_dbase_find_breakpoint_from_line (bd, uri, line_number);
+ }
+
+ if (bi == NULL)
+ {
+ bi = breakpoint_item_new_from_uri (bd, uri, line_number, TRUE);
+
+ breakpoints_dbase_add_breakpoint (bd, bi);
+ }
+ else
+ {
+ breakpoints_dbase_remove_breakpoint (bd, bi);
+ }
+}
+
+/* update the breakpoint with current active line in the editor */
static void
on_toggle_breakpoint_activate (GtkAction * action, BreakpointsDBase *bd)
{
IAnjutaEditor *te;
- BreakpointItem *bi;
GFile* file;
gchar *uri;
guint line;
@@ -1641,24 +1666,29 @@ on_toggle_breakpoint_activate (GtkAction * action, BreakpointsDBase *bd)
uri = g_file_get_uri (file);
g_object_unref (file);
- /* Find corresponding breakpoint
- * Try to find right mark (it could have moved) first */
- bi = breakpoints_dbase_find_breakpoint_from_mark (bd, te, line);
- if (bi == NULL)
- {
- bi = breakpoints_dbase_find_breakpoint_from_line (bd, uri, line);
- }
+ update_breakpoint(bd, te, uri, line);
+
+ g_free (uri);
+}
+
+/* update the breakpoint when the line number is known */
+static void
+on_line_marks_gutter_clicked(GtkAction * action, gint line_number, BreakpointsDBase *bd)
+{
+ IAnjutaEditor *te;
+ GFile* file;
+ gchar *uri;
+
+ /* Get current editor and line */
+ te = dma_get_current_editor (ANJUTA_PLUGIN (bd->plugin));
+ if (te == NULL) return; /* Missing editor */
+ file = ianjuta_file_get_file (IANJUTA_FILE (te), NULL);
+ if (file == NULL) return; /* File not saved yet, it's not possible to put a breakpoint in it */
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+
+ update_breakpoint(bd, te, uri, line_number);
- if (bi == NULL)
- {
- bi = breakpoint_item_new_from_uri (bd, uri, line, TRUE);
-
- breakpoints_dbase_add_breakpoint (bd, bi);
- }
- else
- {
- breakpoints_dbase_remove_breakpoint (bd, bi);
- }
g_free (uri);
}
@@ -2076,3 +2106,8 @@ breakpoints_dbase_destroy (BreakpointsDBase * bd)
g_free (bd);
}
+/* Handler for breakpoint toggle on double clicking line marks gutter */
+void breakpoint_toggle_handler(GtkAction * action, gint line_number, BreakpointsDBase *bd) {
+ /* Simply delegate to an internal API for now */
+ on_line_marks_gutter_clicked (action, line_number, bd);
+}
diff --git a/plugins/debug-manager/breakpoints.h b/plugins/debug-manager/breakpoints.h
index cd500a0..2d2cd5a 100644
--- a/plugins/debug-manager/breakpoints.h
+++ b/plugins/debug-manager/breakpoints.h
@@ -41,6 +41,9 @@ typedef struct _BreakpointsDBase BreakpointsDBase;
BreakpointsDBase *breakpoints_dbase_new (DebugManagerPlugin *plugin);
void breakpoints_dbase_destroy (BreakpointsDBase * bd);
+/* Handler for breakpoint toggle on double clicking line marks gutter */
+void breakpoint_toggle_handler(GtkAction * action, gint line_number, BreakpointsDBase *bd);
+
G_END_DECLS
#endif
diff --git a/plugins/debug-manager/plugin.c b/plugins/debug-manager/plugin.c
index acd7a58..134a418 100644
--- a/plugins/debug-manager/plugin.c
+++ b/plugins/debug-manager/plugin.c
@@ -278,12 +278,34 @@ value_added_current_editor (AnjutaPlugin *plugin, const char *name,
self->current_editor = NULL;
return;
}
-
+
self->current_editor = IANJUTA_EDITOR (editor);
g_object_add_weak_pointer (G_OBJECT (self->current_editor), (gpointer *)(gpointer)&self->current_editor);
/* Restore program counter marker */
show_program_counter_in_editor (self);
+
+ /* connect signal to enable/disable breakpoints on double clicking the line marks gutter */
+ /* firstly, find the handler of previously connected signal */
+ /* secondly, connect signal if a handler wasn't found for the signal */
+ guint signal_id = g_signal_lookup( "line-marks-gutter-clicked", IANJUTA_TYPE_EDITOR);
+ glong handler_id = g_signal_handler_find( (gpointer)self->current_editor,
+ G_SIGNAL_MATCH_ID,
+ signal_id,
+ 0, NULL, NULL, NULL );
+
+
+ DEBUG_PRINT("current editor %p, breapoints db %p", self->current_editor, self->breakpoints);
+
+ if(!handler_id) {
+ g_signal_connect (
+ self->current_editor,
+ "line-marks-gutter-clicked",
+ G_CALLBACK (breakpoint_toggle_handler),
+ self->breakpoints
+ );
+ }
+
}
static void
diff --git a/plugins/sourceview/sourceview.c b/plugins/sourceview/sourceview.c
index 2fd2003..1567c2f 100644
--- a/plugins/sourceview/sourceview.c
+++ b/plugins/sourceview/sourceview.c
@@ -319,6 +319,28 @@ static void on_backspace (GtkTextView* view,
g_signal_emit_by_name(G_OBJECT(sv), "update_ui");
}
+static void
+on_line_mark_activated(GtkTextView* view,
+ GtkTextIter *iter,
+ GdkEventButton *event,
+ Sourceview* sv)
+{
+ /* proceed only if its a double click with left button*/
+ if( (event->button != 1) || (GDK_2BUTTON_PRESS != event->type) ) {
+ return;
+ }
+
+ /* line number starts with 0, so add 1 */
+ gint line_number = gtk_text_iter_get_line(iter)+1;
+
+ if (!IANJUTA_IS_EDITOR(sv))
+ {
+ return;
+ }
+ g_signal_emit_by_name(G_OBJECT(sv), "line-marks-gutter-clicked", line_number);
+}
+
+
/* Open / Save stuff */
/* Callback for dialog below */
@@ -647,6 +669,7 @@ sourceview_instance_init(Sourceview* sv)
G_CALLBACK (on_sourceview_hover_over), sv);
g_signal_connect_after(G_OBJECT(sv->priv->view), "backspace",
G_CALLBACK(on_backspace),sv);
+
g_object_set (G_OBJECT (sv->priv->view), "has-tooltip", TRUE, NULL);
gtk_source_view_set_smart_home_end(GTK_SOURCE_VIEW(sv->priv->view), FALSE);
@@ -741,6 +764,10 @@ sourceview_new(GFile* file, const gchar* filename, AnjutaPlugin* plugin)
DEBUG_PRINT("%s", "============ Creating new editor =============");
g_signal_emit_by_name (G_OBJECT(sv), "update-ui");
+ g_signal_connect_after(G_OBJECT(sv->priv->view), "line-mark-activated",
+ G_CALLBACK(on_line_mark_activated),
+ G_OBJECT(sv)
+ );
return sv;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]