[gnome-builder/wip/chergert/hover] toggle state



commit df8cf22f6304ede62a577c8e3dcec5d645752030
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jul 2 18:54:35 2018 -0700

    toggle state

 src/libide/debugger/ide-debugger-hover-controls.c | 88 ++++++++++++++++++++++-
 1 file changed, 87 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/debugger/ide-debugger-hover-controls.c 
b/src/libide/debugger/ide-debugger-hover-controls.c
index 2043c084a..10cae5c72 100644
--- a/src/libide/debugger/ide-debugger-hover-controls.c
+++ b/src/libide/debugger/ide-debugger-hover-controls.c
@@ -20,9 +20,13 @@
 
 #define G_LOG_DOMAIN "ide-debugger-hover-controls"
 
+#include <dazzle.h>
+
 #include "debugger/ide-debugger-hover-controls.h"
 #include "debugger/ide-debugger-breakpoints.h"
+#include "debugger/ide-debugger-private.h"
 #include "debugger/ide-debug-manager.h"
+#include "sourceview/ide-source-view.h"
 
 struct _IdeDebuggerHoverControls
 {
@@ -69,13 +73,91 @@ ide_debugger_hover_controls_init (IdeDebuggerHoverControls *self)
   gtk_widget_init_template (GTK_WIDGET (self));
 }
 
+static void
+on_toggle_cb (GtkToggleButton          *button,
+              IdeDebuggerHoverControls *self)
+{
+  g_autoptr(IdeDebuggerBreakpoints) breakpoints = NULL;
+  IdeDebuggerBreakMode break_type = IDE_DEBUGGER_BREAK_NONE;
+  IdeDebuggerBreakpoint *breakpoint;
+  GtkWidget *view;
+
+  g_assert (GTK_IS_TOGGLE_BUTTON (button));
+  g_assert (IDE_IS_DEBUGGER_HOVER_CONTROLS (self));
+
+  g_signal_handlers_block_by_func (self->nobreak, G_CALLBACK (on_toggle_cb), self);
+  g_signal_handlers_block_by_func (self->breakpoint, G_CALLBACK (on_toggle_cb), self);
+  g_signal_handlers_block_by_func (self->countpoint, G_CALLBACK (on_toggle_cb), self);
+
+  breakpoints = ide_debug_manager_get_breakpoints_for_file (self->debug_manager, self->file);
+  breakpoint = ide_debugger_breakpoints_get_line (breakpoints, self->line);
+
+  if (button == self->nobreak)
+    break_type = IDE_DEBUGGER_BREAK_NONE;
+  else if (button == self->breakpoint)
+    break_type = IDE_DEBUGGER_BREAK_BREAKPOINT;
+  else if (button == self->countpoint)
+    break_type = IDE_DEBUGGER_BREAK_COUNTPOINT;
+
+  if (breakpoint != NULL)
+    {
+      _ide_debug_manager_remove_breakpoint (self->debug_manager, breakpoint);
+      breakpoint = NULL;
+    }
+
+  switch (break_type)
+    {
+    default:
+    case IDE_DEBUGGER_BREAK_NONE:
+      gtk_toggle_button_set_active (self->nobreak, TRUE);
+      gtk_toggle_button_set_active (self->breakpoint, FALSE);
+      gtk_toggle_button_set_active (self->countpoint, FALSE);
+      break;
+
+    case IDE_DEBUGGER_BREAK_BREAKPOINT:
+    case IDE_DEBUGGER_BREAK_COUNTPOINT:
+      {
+        g_autoptr(IdeDebuggerBreakpoint) to_insert = NULL;
+        g_autofree gchar *path = g_file_get_path (self->file);
+
+        to_insert = ide_debugger_breakpoint_new (NULL);
+
+        ide_debugger_breakpoint_set_line (to_insert, self->line);
+        ide_debugger_breakpoint_set_file (to_insert, path);
+        ide_debugger_breakpoint_set_mode (to_insert, break_type);
+        ide_debugger_breakpoint_set_enabled (to_insert, TRUE);
+
+        _ide_debug_manager_add_breakpoint (self->debug_manager, to_insert);
+
+        gtk_toggle_button_set_active (self->nobreak, FALSE);
+        gtk_toggle_button_set_active (self->breakpoint, break_type == IDE_DEBUGGER_BREAK_BREAKPOINT);
+        gtk_toggle_button_set_active (self->countpoint, break_type == IDE_DEBUGGER_BREAK_COUNTPOINT);
+      }
+      break;
+
+    case IDE_DEBUGGER_BREAK_WATCHPOINT:
+      /* TODO: watchpoint not yet supported */
+      gtk_toggle_button_set_active (self->nobreak, FALSE);
+      gtk_toggle_button_set_active (self->breakpoint, FALSE);
+      gtk_toggle_button_set_active (self->countpoint, FALSE);
+      break;
+    }
+
+  view = dzl_gtk_widget_get_relative (GTK_WIDGET (self), IDE_TYPE_SOURCE_VIEW);
+  gtk_widget_queue_draw (view);
+
+  g_signal_handlers_unblock_by_func (self->nobreak, G_CALLBACK (on_toggle_cb), self);
+  g_signal_handlers_unblock_by_func (self->breakpoint, G_CALLBACK (on_toggle_cb), self);
+  g_signal_handlers_unblock_by_func (self->countpoint, G_CALLBACK (on_toggle_cb), self);
+}
+
 GtkWidget *
 ide_debugger_hover_controls_new (IdeDebugManager *debug_manager,
                                  GFile           *file,
                                  guint            line)
 {
+  g_autoptr(IdeDebuggerBreakpoints) breakpoints = NULL;
   IdeDebuggerHoverControls *self;
-  IdeDebuggerBreakpoints *breakpoints;
 
   self = g_object_new (IDE_TYPE_DEBUGGER_HOVER_CONTROLS, NULL);
   self->debug_manager = g_object_ref (debug_manager);
@@ -109,5 +191,9 @@ ide_debugger_hover_controls_new (IdeDebugManager *debug_manager,
         }
     }
 
+  g_signal_connect (self->nobreak, "toggled", G_CALLBACK (on_toggle_cb), self);
+  g_signal_connect (self->breakpoint, "toggled", G_CALLBACK (on_toggle_cb), self);
+  g_signal_connect (self->countpoint, "toggled", G_CALLBACK (on_toggle_cb), self);
+
   return GTK_WIDGET (self);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]