[gnome-builder/wip/albfan/debug-expressions: 168/168] debugger: Add debug expressions
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/albfan/debug-expressions: 168/168] debugger: Add debug expressions
- Date: Sun, 7 Oct 2018 23:18:07 +0000 (UTC)
commit 5ba22bb06b9576a7a975dae2c516165f28d6e975
Author: albfan <albertofanjul gmail com>
Date: Sat Apr 28 09:28:17 2018 +0200
debugger: Add debug expressions
Interface to add new expressions
Tree node to see expressions evaluated
src/libide/debugger/gtk/menus.ui | 8 ++
src/libide/debugger/ide-debugger-actions.c | 64 +++++++++++++
src/libide/debugger/ide-debugger-locals-view.c | 117 ++++++++++++++++++++++++
src/libide/debugger/ide-debugger-locals-view.ui | 1 +
4 files changed, 190 insertions(+)
---
diff --git a/src/libide/debugger/gtk/menus.ui b/src/libide/debugger/gtk/menus.ui
index 332fc237b..25d83b539 100644
--- a/src/libide/debugger/gtk/menus.ui
+++ b/src/libide/debugger/gtk/menus.ui
@@ -13,4 +13,12 @@
</item>
</section>
</menu>
+ <menu id="ide-debugger-view-locals-popup-menu">
+ <section id="ide-debugger-view-locals-popup-menu-section">
+ <item>
+ <attribute name="label" translatable="yes">_Watch expression...</attribute>
+ <attribute name="action">debugger.watch-expression</attribute>
+ </item>
+ </section>
+ </menu>
</interface>
diff --git a/src/libide/debugger/ide-debugger-actions.c b/src/libide/debugger/ide-debugger-actions.c
index b635c32ad..fddb029b2 100644
--- a/src/libide/debugger/ide-debugger-actions.c
+++ b/src/libide/debugger/ide-debugger-actions.c
@@ -74,6 +74,69 @@ check_running_state (IdeDebugger *self,
return TRUE;
}
+static void
+ide_debugger_watch_expression (IdeDebugger *self,
+ const IdeDebuggerActionEntry *entry,
+ GVariant *param)
+{
+ g_assert (IDE_IS_DEBUGGER (self));
+ g_assert (entry != NULL);
+
+ /*GtkBuilder *builder;*/
+ /*GObject *window;*/
+ /*GObject *button;*/
+
+ /*builder = gtk_builder_new ();*/
+ /*gtk_builder_add_from_file (builder, "builder.ui", NULL);*/
+
+
+ /*GtkBuilder *builder;*/
+ /*GtkWidget *palettes_placeholder;*/
+
+ /*g_type_ensure (GB_TYPE_COLOR_PICKER_PREFS_LIST);*/
+ /*g_type_ensure (GB_TYPE_COLOR_PICKER_PREFS_PALETTE_LIST);*/
+
+ /*builder = gtk_builder_new_from_resource
("/org/gnome/builder/plugins/color-picker-plugin/gtk/color-picker-prefs.ui");*/
+
+ /*self->palettes_box = GB_COLOR_PICKER_PREFS_PALETTE_LIST (gtk_builder_get_object (builder,
"palettes_box"));*/
+ /*palettes_placeholder = GTK_WIDGET (gtk_builder_get_object (builder, "palettes_placeholder"));*/
+
+ /*[> Connect signal handlers to the constructed widgets. <]*/
+ /*window = gtk_builder_get_object (builder, "window");*/
+ /*g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);*/
+
+ /*button = gtk_builder_get_object (builder, "button1");*/
+ /*g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);*/
+
+ /*button = gtk_builder_get_object (builder, "button2");*/
+ /*g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);*/
+ /*//TODO: Add a dialog for a new expression*/
+ /*GtkWidget *main_app_window; // Window the dialog should show up on*/
+ /*GtkWidget *dialog;*/
+ /*GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;*/
+ /*dialog = gtk_dialog_new_with_buttons ("My dialog",*/
+ /*main_app_window,*/
+ /*flags,*/
+ /*_("_OK"),*/
+ /*GTK_RESPONSE_ACCEPT,*/
+ /*_("_Cancel"),*/
+ /*GTK_RESPONSE_REJECT,*/
+ /*NULL);*/
+
+ /*int result = gtk_dialog_run (GTK_DIALOG (dialog));*/
+ /*switch (result)*/
+ /*{*/
+ /*case GTK_RESPONSE_ACCEPT:*/
+ /*// do_application_specific_something ();*/
+ /*break;*/
+ /*default:*/
+ /*// do_nothing_since_dialog_was_cancelled ();*/
+ /*break;*/
+ /*}*/
+ /*gtk_widget_destroy (dialog);*/
+
+}
+
static void
ide_debugger_actions_movement (IdeDebugger *self,
const IdeDebuggerActionEntry *entry,
@@ -103,6 +166,7 @@ static IdeDebuggerActionEntry action_info[] = {
{ "step-in", ide_debugger_actions_movement, IDE_DEBUGGER_MOVEMENT_STEP_IN, RUNNING_STARTED |
RUNNING_NOT_ACTIVE },
{ "step-over", ide_debugger_actions_movement, IDE_DEBUGGER_MOVEMENT_STEP_OVER, RUNNING_STARTED |
RUNNING_NOT_ACTIVE },
{ "finish", ide_debugger_actions_movement, IDE_DEBUGGER_MOVEMENT_FINISH, RUNNING_STARTED |
RUNNING_NOT_ACTIVE },
+ { "watch-expression", ide_debugger_watch_expression, IDE_DEBUGGER_MOVEMENT_FINISH, RUNNING_STARTED |
RUNNING_NOT_ACTIVE },
};
static gboolean
diff --git a/src/libide/debugger/ide-debugger-locals-view.c b/src/libide/debugger/ide-debugger-locals-view.c
index 97ebb1f74..e91348751 100644
--- a/src/libide/debugger/ide-debugger-locals-view.c
+++ b/src/libide/debugger/ide-debugger-locals-view.c
@@ -215,6 +215,68 @@ ide_debugger_locals_view_class_init (IdeDebuggerLocalsViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, IdeDebuggerLocalsView, variable_column);
}
+static gboolean
+ide_debugger_locals_button_press (GtkWidget *widget,
+ GdkEventButton *bevent)
+{
+ GtkTreeView *self = (GtkTreeView *)widget;
+ GMenu *menu;
+ GtkWidget *menu_widget;
+ gint cell_y;
+ GtkTreePath *tree_path = NULL;
+ GtkAllocation alloc;
+
+ if ((bevent->type == GDK_BUTTON_PRESS) && (bevent->button == GDK_BUTTON_SECONDARY))
+ {
+ if (!gtk_widget_has_focus (GTK_WIDGET (self)))
+ gtk_widget_grab_focus (GTK_WIDGET (self));
+
+ gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (self),
+ bevent->x,
+ bevent->y,
+ &tree_path,
+ NULL,
+ NULL,
+ &cell_y);
+
+ if (tree_path)
+ {
+ //gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
+ //gtk_tree_model_get_iter (GTK_TREE_MODEL (self->tree_store), &iter, tree_path);
+ //gtk_tree_model_get (GTK_TREE_MODEL (self->tree_store), &iter, 0, &node, -1);
+
+ menu = dzl_application_get_menu_by_id (DZL_APPLICATION_DEFAULT,
+ "ide-debugger-view-locals-popup-menu");
+ menu_widget = gtk_menu_new_from_model (G_MENU_MODEL (menu));
+
+ gtk_menu_attach_to_widget (GTK_MENU(menu_widget),
+ GTK_WIDGET (self),
+ NULL);
+ g_signal_connect_after (menu,
+ "selection-done",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+
+ g_object_set (G_OBJECT (menu),
+ "rect-anchor-dx", alloc.x + alloc.width - 12,
+ "rect-anchor-dy", bevent->y - cell_y - 3,
+ NULL);
+ gtk_menu_popup_at_widget (GTK_MENU (menu_widget),
+ GTK_WIDGET (self),
+ GDK_GRAVITY_NORTH_WEST,
+ GDK_GRAVITY_NORTH_WEST,
+ (GdkEvent *)bevent);
+ //g_object_unref (node);
+ gtk_tree_path_free (tree_path);
+ }
+
+ return GDK_EVENT_STOP;
+ }
+
+ return GDK_EVENT_STOP;
+ //return GTK_WIDGET_CLASS (ide_tree_parent_class)->button_press_event (widget, button);
+}
+
static void
ide_debugger_locals_view_init (IdeDebuggerLocalsView *self)
{
@@ -243,6 +305,8 @@ ide_debugger_locals_view_init (IdeDebuggerLocalsView *self)
gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (self->value_column),
GTK_CELL_RENDERER (self->value_cell),
string_property_cell_data_func, (gchar *)"value", NULL);
+
+ g_signal_connect(self->tree_view, "button-press-event", (GCallback) ide_debugger_locals_button_press,
NULL);
}
GtkWidget *
@@ -386,6 +450,57 @@ ide_debugger_locals_view_load_params_cb (GObject *object,
}
}
+void
+ide_debugger_list_expressions (IdeDebuggerLocalsView *self, IdeDebugger *debugger)
+{
+ g_autoptr(GPtrArray) expressions = NULL;
+ GtkTreeIter parent;
+ IdeDebuggerVariable *var;
+
+ g_assert (IDE_IS_DEBUGGER (debugger));
+ g_assert (IDE_IS_DEBUGGER_LOCALS_VIEW (self));
+
+ expressions = g_ptr_array_new ();
+ var = ide_debugger_variable_new ("foo");
+ ide_debugger_variable_set_type_name (var, "char*");
+ ide_debugger_variable_set_value (var, "hola");
+ g_ptr_array_add (expressions, g_steal_pointer (&var));
+
+ var = ide_debugger_variable_new ("bar");
+ ide_debugger_variable_set_type_name (var, "char*");
+ ide_debugger_variable_set_value (var, "adios");
+ g_ptr_array_add (expressions, g_steal_pointer (&var));
+
+ var = ide_debugger_variable_new ("bazz");
+ ide_debugger_variable_set_type_name (var, "char*");
+ ide_debugger_variable_set_value (var, "eco");
+ g_ptr_array_add (expressions, g_steal_pointer (&var));
+
+ gtk_tree_store_append (self->tree_store, &parent, NULL);
+ gtk_tree_store_set (self->tree_store, &parent, 1, _("Expressions"), -1);
+
+ for (guint i = 0; i < expressions->len; i++)
+ {
+ var = g_ptr_array_index (expressions, i);
+ GtkTreeIter iter;
+
+ gtk_tree_store_append (self->tree_store, &iter, &parent);
+ gtk_tree_store_set (self->tree_store, &iter, 0, var, -1);
+
+ /* Add a deummy row that we can backfill when the user requests
+ * that the variable is expanded.
+ */
+ if (ide_debugger_variable_get_has_children (var))
+ {
+ GtkTreeIter dummy;
+
+ gtk_tree_store_append (self->tree_store, &dummy, &iter);
+ }
+ }
+
+ gtk_tree_view_expand_all (self->tree_view);
+}
+
void
ide_debugger_locals_view_load_async (IdeDebuggerLocalsView *self,
IdeDebuggerThread *thread,
@@ -429,6 +544,8 @@ ide_debugger_locals_view_load_async (IdeDebuggerLocalsView *self,
cancellable,
ide_debugger_locals_view_load_locals_cb,
g_steal_pointer (&task));
+
+ ide_debugger_list_expressions (self, debugger);
}
gboolean
diff --git a/src/libide/debugger/ide-debugger-locals-view.ui b/src/libide/debugger/ide-debugger-locals-view.ui
index 2c8515100..8032ae68c 100644
--- a/src/libide/debugger/ide-debugger-locals-view.ui
+++ b/src/libide/debugger/ide-debugger-locals-view.ui
@@ -17,6 +17,7 @@
<child>
<object class="GtkCellRendererText" id="variable_cell">
<property name="xalign">0.0</property>
+ <property name="editable">1</property>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]