SF.net SVN: geany-plugins:[2116] trunk/geany-plugins/debugger/src

cesspit at users.sourceforge.net cesspit at xxxxx
Tue Aug 2 21:05:20 UTC 2011


Revision: 2116
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2116&view=rev
Author:   cesspit
Date:     2011-08-02 21:05:20 +0000 (Tue, 02 Aug 2011)

Log Message:
-----------
debugger runtime calltips appearance improving

Modified Paths:
--------------
    trunk/geany-plugins/debugger/src/Makefile.am
    trunk/geany-plugins/debugger/src/callbacks.c
    trunk/geany-plugins/debugger/src/dbm_gdb.c
    trunk/geany-plugins/debugger/src/debug.c
    trunk/geany-plugins/debugger/src/debug.h

Added Paths:
-----------
    trunk/geany-plugins/debugger/src/calltip.c
    trunk/geany-plugins/debugger/src/calltip.h

Modified: trunk/geany-plugins/debugger/src/Makefile.am
===================================================================
--- trunk/geany-plugins/debugger/src/Makefile.am	2011-08-02 14:03:25 UTC (rev 2115)
+++ trunk/geany-plugins/debugger/src/Makefile.am	2011-08-02 21:05:20 UTC (rev 2116)
@@ -15,6 +15,8 @@
 	breakpoints.h     \
 	callbacks.c     \
 	callbacks.h     \
+	calltip.c     \
+	calltip.h     \
 	dbm_gdb.c     \
 	debug.c     \
 	debug.h     \

Modified: trunk/geany-plugins/debugger/src/callbacks.c
===================================================================
--- trunk/geany-plugins/debugger/src/callbacks.c	2011-08-02 14:03:25 UTC (rev 2115)
+++ trunk/geany-plugins/debugger/src/callbacks.c	2011-08-02 21:05:20 UTC (rev 2116)
@@ -33,6 +33,7 @@
 #include "keys.h"
 #include "tpage.h"
 #include "stree.h"
+#include "markers.h"
 #include "utils.h"
 
 extern GeanyFunctions *geany_functions;
@@ -87,6 +88,9 @@
 	/*set dwell interval*/
 	scintilla_send_message(doc->editor->sci, SCI_SETMOUSEDWELLTIME, 500, 0);
 
+	/* set tab size for calltips */
+	scintilla_send_message(doc->editor->sci, SCI_CALLTIPUSESTYLE, 20, NULL);
+
 	/* set caret policy */
 	scintilla_send_message(doc->editor->sci, SCI_SETYCARETPOLICY, CARET_SLOP | CARET_JUMPS | CARET_EVEN , 3);
 	
@@ -139,15 +143,11 @@
 
 			if (word->len)
 			{
-				/* evaluate expression */
-				gchar *value = debug_evaluate_expression (word->str);
-				if (value)
+				GString *calltip = debug_get_calltip_for_expression(word->str);
+				if (calltip)
 				{
-					/* create and show calltip */
-					gchar* msg = g_strdup_printf("%s = %s", word->str, value) ;
-					scintilla_send_message (editor->sci, SCI_CALLTIPSHOW, nt->position, (long)msg);
-					g_free(msg);
-					g_free(value);
+					scintilla_send_message (editor->sci, SCI_CALLTIPSHOW, nt->position, (long)calltip->str);
+					g_string_free(calltip, TRUE);
 				}
 			}
 				
@@ -157,6 +157,9 @@
 		}
 		case SCN_DWELLEND:
 		{
+			if (DBS_STOPPED != debug_get_state ())
+				break;
+
 			scintilla_send_message (editor->sci, SCI_CALLTIPCANCEL, 0, 0);
 			break;
 		}

Added: trunk/geany-plugins/debugger/src/calltip.c
===================================================================
--- trunk/geany-plugins/debugger/src/calltip.c	                        (rev 0)
+++ trunk/geany-plugins/debugger/src/calltip.c	2011-08-02 21:05:20 UTC (rev 2116)
@@ -0,0 +1,72 @@
+/*
+ *		calltip.c
+ *      
+ *      Copyright 2011 Alexander Petukhov <devel(at)apetukhov(dot)ru>
+ *      
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *      
+ *      This program is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *      GNU General Public License for more details.
+ *      
+ *      You should have received a copy of the GNU General Public License
+ *      along with this program; if not, write to the Free Software
+ *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *      MA 02110-1301, USA.
+ */
+
+/*
+ *		Formatting calltip text.
+ */
+
+#include <gtk/gtk.h>
+
+#include "breakpoint.h"
+#include "debug_module.h"
+#include "calltip.h"
+
+#define FIRST_LINE "\002\t%s = (%s) %s"
+#define FIRST_LINE_NO_CHILDERN "%s = (%s) %s"
+#define REST_LINES "\t▸\t%s = (%s) %s"
+#define REST_LINES_NO_CHILDERN "\t\t%s = (%s) %s"
+
+/*
+ * creates text for a tooltip taking list or variables   
+ */
+GString* get_calltip_line(variable *var, gboolean firstline)
+{
+	GString *calltip = NULL;
+	if (var && var->evaluated)
+	{
+		calltip = g_string_new("");
+		if (firstline)
+		{
+			g_string_append_printf(calltip,
+				var->has_children ? FIRST_LINE : FIRST_LINE_NO_CHILDERN,
+				var->name->str,
+				var->type->str,
+				var->value->str);
+		}
+		else
+		{
+			g_string_append_printf(calltip,
+				var->has_children ? REST_LINES : REST_LINES_NO_CHILDERN,
+				var->name->str,
+				var->type->str,
+				var->value->str);
+		}
+
+		if (calltip->len > MAX_CALLTIP_LENGTH)
+		{
+			g_string_truncate(calltip, MAX_CALLTIP_LENGTH);
+			g_string_append(calltip, " ...");
+		}	
+	}
+
+	return calltip;
+}
+

Added: trunk/geany-plugins/debugger/src/calltip.h
===================================================================
--- trunk/geany-plugins/debugger/src/calltip.h	                        (rev 0)
+++ trunk/geany-plugins/debugger/src/calltip.h	2011-08-02 21:05:20 UTC (rev 2116)
@@ -0,0 +1,25 @@
+/*
+ *		calltip.h
+ *      
+ *      Copyright 2010 Alexander Petukhov <Alexander(dot)Petukhov(at)mail(dot)ru>
+ *      
+ *      This program is free software; you can redistribute it and/or modify
+ *      it under the terms of the GNU General Public License as published by
+ *      the Free Software Foundation; either version 2 of the License, or
+ *      (at your option) any later version.
+ *      
+ *      This program is distributed in the hope that it will be useful,
+ *      but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *      GNU General Public License for more details.
+ *      
+ *      You should have received a copy of the GNU General Public License
+ *      along with this program; if not, write to the Free Software
+ *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ *      MA 02110-1301, USA.
+ */
+ 
+#define MAX_CALLTIP_LENGTH 140
+#define MAX_CALLTIP_HEIGHT 20
+
+GString* get_calltip_line(variable *var, gboolean firstline);

Modified: trunk/geany-plugins/debugger/src/dbm_gdb.c
===================================================================
--- trunk/geany-plugins/debugger/src/dbm_gdb.c	2011-08-02 14:03:25 UTC (rev 2115)
+++ trunk/geany-plugins/debugger/src/dbm_gdb.c	2011-08-02 21:05:20 UTC (rev 2116)
@@ -1430,16 +1430,16 @@
 /*
  * remove watch 
  */
-void remove_watch(gchar* path)
+void remove_watch(gchar* internal)
 {
 	GList *iter = watches;
 	while (iter)
 	{
 		variable *var = (variable*)iter->data;
-		if (!strcmp(var->name->str, path))
+		if (!strcmp(var->internal->str, internal))
 		{
 			gchar command[1000];
-			sprintf(command, "-var-delete %s", var->internal->str);
+			sprintf(command, "-var-delete %s", internal);
 			exec_sync_command(command, TRUE, NULL);
 			watches = g_list_delete_link(watches, iter);
 		}

Modified: trunk/geany-plugins/debugger/src/debug.c
===================================================================
--- trunk/geany-plugins/debugger/src/debug.c	2011-08-02 14:03:25 UTC (rev 2115)
+++ trunk/geany-plugins/debugger/src/debug.c	2011-08-02 21:05:20 UTC (rev 2116)
@@ -52,7 +52,14 @@
 #include "wtree.h"
 #include "ltree.h"
 #include "tpage.h"
+#include "calltip.h"
 
+/*
+ *  calltip size  
+ */ 
+#define CALLTIP_HEIGHT 20
+#define CALLTIP_WIDTH 200
+
 /* module description structure (name/module pointer) */
 typedef struct _module_description {
 	gchar *title;
@@ -162,6 +169,12 @@
 		&iter,
 		W_NAME, &oldvalue,
        -1);
+	gchar *internal = NULL;
+		gtk_tree_model_get (
+		wmodel,
+		&iter,
+		W_INTERNAL, &internal,
+		1);
 
 	/* check if it is empty row */
 	gboolean is_empty_row = !gtk_tree_path_compare (tree_path, wtree_empty_path());
@@ -175,7 +188,7 @@
 		 * offer to delete watch */
 		gtk_tree_store_remove(wstore, &iter);
 		if (DBS_STOPPED == debug_state)
-			active_module->remove_watch(oldvalue);
+			active_module->remove_watch(internal);
 	}
 	else if (strcmp(oldvalue, striped))
     {
@@ -192,7 +205,7 @@
 		/* if debug is active - remove old watch and add new one */
 		if (DBS_STOPPED == debug_state)
 		{
-			active_module->remove_watch(oldvalue);
+			active_module->remove_watch(internal);
 			variable *newvar = active_module->add_watch(striped);
 			change_watch(GTK_TREE_VIEW(wtree), is_empty_row ? &newiter : &iter, newvar);
 		}
@@ -211,6 +224,7 @@
 	/* free resources */
 	gtk_tree_path_free(tree_path);
 	g_free(oldvalue);
+	g_free(internal);
 	g_free(striped);
 }
 
@@ -350,16 +364,16 @@
 				if (DBS_STOPPED == debug_state)
 				{
 
-					gchar *name = NULL;
+					gchar *internal = NULL;
 					gtk_tree_model_get (
 						wmodel,
 						&titer,
-						W_NAME, &name,
+						W_INTERNAL, &internal,
 						-1);
 
-					active_module->remove_watch(name);
+					active_module->remove_watch(internal);
 
-					g_free(name);
+					g_free(internal);
 				}
 
 
@@ -556,8 +570,8 @@
 	/* get current stack trace and put in the tree view */
 	GList* stack = active_module->get_stack();
 
-	/* if upper frame has source file - remember file anf line for
-	current instruction marker */
+	/* if upper frame has source file - remember the file and the line for
+	the current instruction marker */
 	frame *f = (frame*)stack->data;
 	if (f->have_source)
 	{
@@ -828,7 +842,7 @@
 	/* create debug terminal page */
 	terminal = vte_terminal_new();
 	/* create PTY */
-	int res = openpty(&pty_master, &pty_slave, NULL,
+	openpty(&pty_master, &pty_slave, NULL,
 		    NULL,
 		    NULL);
 	grantpt(pty_master);
@@ -862,7 +876,6 @@
 		GTK_POLICY_AUTOMATIC);
 	hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(sview));
 	vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(sview));
-	GtkWidget* viewport = gtk_viewport_new(hadj, vadj);
 	
 	debugger_messages_textview =  gtk_text_view_new();
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(debugger_messages_textview), GTK_WRAP_CHAR);
@@ -1144,6 +1157,48 @@
 }
 
 /*
+ * return list of strings for the calltip
+ * first line is a header, others should be shifted right with tab
+ */
+GString* debug_get_calltip_for_expression(gchar* expression)
+{
+	GString *calltip = NULL;
+
+	variable *var = active_module->add_watch(expression);
+	if (var)
+	{
+		calltip = get_calltip_line(var, TRUE);
+		if (var->has_children)
+		{
+			int lines_left = MAX_CALLTIP_HEIGHT - 1;
+			GList* children = active_module->get_children(var->internal->str); 
+			GList* child = children;
+			while(child && lines_left)
+			{
+				variable *varchild = (variable*)child->data;
+				GString *child_string = get_calltip_line(varchild, FALSE);
+				g_string_append_printf(calltip, "\n%s", child_string->str);
+				g_string_free(child_string, TRUE);
+
+				child = child->next;
+				lines_left--;
+			}
+			if (!lines_left && child)
+			{
+				g_string_append(calltip, "\n\t\t........");
+			}
+			g_list_foreach(children, (GFunc)variable_free, NULL);
+			g_list_free(children);
+		}
+
+		active_module->remove_watch(var->internal->str);
+		variable_free(var);
+	}
+	
+	return calltip;
+}
+
+/*
  * check whether source for the current instruction
  * is avaiable
  */

Modified: trunk/geany-plugins/debugger/src/debug.h
===================================================================
--- trunk/geany-plugins/debugger/src/debug.h	2011-08-02 14:03:25 UTC (rev 2115)
+++ trunk/geany-plugins/debugger/src/debug.h	2011-08-02 21:05:20 UTC (rev 2116)
@@ -20,6 +20,7 @@
  */
  
 #include "debug_module.h"
+#include "markers.h"
 
 /* debug states enumeration */
 enum dbs {
@@ -53,4 +54,5 @@
 gboolean	debug_current_instruction_have_sources();
 void		debug_jump_to_current_instruction();
 void		debug_on_file_open(GeanyDocument *doc);
+GString* debug_get_calltip_for_expression(gchar* expression);
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list