SF.net SVN: geany:[5887] trunk

colombanw at users.sourceforge.net colombanw at xxxxx
Sat Aug 13 20:44:39 UTC 2011


Revision: 5887
          http://geany.svn.sourceforge.net/geany/?rev=5887&view=rev
Author:   colombanw
Date:     2011-08-13 20:44:39 +0000 (Sat, 13 Aug 2011)

Log Message:
-----------
Focus the editor upon double click on the message and compiler windows

Also improve the code a bit by using a boolean to know whether to focus
the editor rather than always pass the key value and check it against
enter-or-return in the callee side.

Patch by Dimitar Zhekov, thanks!

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/msgwindow.c
    trunk/src/msgwindow.h
    trunk/src/ui_utils.c
    trunk/src/ui_utils.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2011-08-06 18:34:14 UTC (rev 5886)
+++ trunk/ChangeLog	2011-08-13 20:44:39 UTC (rev 5887)
@@ -1,3 +1,10 @@
+2011-08-13  Colomban Wendling  <colomban(at)geany(dot)org>
+
+ * src/msgwindow.c, src/msgwindow.h, src/ui_utils.c, src/ui_utils.h:
+   Focus the editor upon double click on the message and compiler
+   windows (patch by Dimitar Zhekov, thanks).
+
+
 2011-08-03  Colomban Wendling  <colomban(at)geany(dot)org>
 
  * src/geany.h, plugins/classbuilder.c, plugins/export.c,

Modified: trunk/src/msgwindow.c
===================================================================
--- trunk/src/msgwindow.c	2011-08-06 18:34:14 UTC (rev 5886)
+++ trunk/src/msgwindow.c	2011-08-13 20:44:39 UTC (rev 5887)
@@ -124,18 +124,20 @@
 
 static gboolean on_msgwin_key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-	if (ui_is_keyval_enter_or_return(event->keyval) || event->keyval == GDK_space)
+	gboolean enter_or_return = ui_is_keyval_enter_or_return(event->keyval);
+
+	if (enter_or_return || event->keyval == GDK_space)
 	{
 		switch (GPOINTER_TO_INT(data))
 		{
 			case MSG_COMPILER:
-			{	/* single click in the compiler treeview */
-				msgwin_goto_compiler_file_line(event->keyval);
+			{	/* key press in the compiler treeview */
+				msgwin_goto_compiler_file_line(enter_or_return);
 				break;
 			}
 			case MSG_MESSAGE:
-			{	/* single click in the message treeview (results of 'Find usage') */
-				msgwin_goto_messages_file_line(event->keyval);
+			{	/* key press in the message treeview (results of 'Find usage') */
+				msgwin_goto_messages_file_line(enter_or_return);
 				break;
 			}
 		}
@@ -194,6 +196,9 @@
 	 * (connect_after button-press-event doesn't work) */
 	g_signal_connect(msgwindow.tree_msg, "button-release-event",
 					G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_MESSAGE));
+	/* for double-clicking only, after the first release */
+	g_signal_connect(msgwindow.tree_msg, "button-press-event",
+					G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_MESSAGE));
 	g_signal_connect(msgwindow.tree_msg, "key-press-event",
 		G_CALLBACK(on_msgwin_key_press_event), GINT_TO_POINTER(MSG_MESSAGE));
 
@@ -227,6 +232,9 @@
 	 * (connect_after button-press-event doesn't work) */
 	g_signal_connect(msgwindow.tree_compiler, "button-release-event",
 					G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_COMPILER));
+	/* for double-clicking only, after the first release */
+	g_signal_connect(msgwindow.tree_compiler, "button-press-event",
+					G_CALLBACK(on_msgwin_button_press_event), GINT_TO_POINTER(MSG_COMPILER));
 	g_signal_connect(msgwindow.tree_compiler, "key-press-event",
 		G_CALLBACK(on_msgwin_key_press_event), GINT_TO_POINTER(MSG_COMPILER));
 
@@ -619,7 +627,7 @@
 }
 
 
-static gboolean goto_compiler_file_line(const gchar *filename, gint line, guint keyval)
+static gboolean goto_compiler_file_line(const gchar *filename, gint line, gboolean focus_editor)
 {
 	if (!filename || line <= -1)
 		return FALSE;
@@ -669,7 +677,7 @@
 				editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1);
 
 			ret = navqueue_goto_line(old_doc, doc, line);
-			if (ret && ui_is_keyval_enter_or_return(keyval))
+			if (ret && focus_editor)
 				gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
 
 			return ret;
@@ -679,7 +687,7 @@
 }
 
 
-gboolean msgwin_goto_compiler_file_line(guint keyval)
+gboolean msgwin_goto_compiler_file_line(gboolean focus_editor)
 {
 	GtkTreeIter iter;
 	GtkTreeModel *model;
@@ -715,7 +723,7 @@
 			g_free(string);
 			g_free(dir);
 
-			ret = goto_compiler_file_line(filename, line, keyval);
+			ret = goto_compiler_file_line(filename, line, focus_editor);
 			g_free(filename);
 			return ret;
 		}
@@ -1037,7 +1045,7 @@
 }
 
 
-gboolean msgwin_goto_messages_file_line(guint keyval)
+gboolean msgwin_goto_messages_file_line(gboolean focus_editor)
 {
 	GtkTreeIter iter;
 	GtkTreeModel *model;
@@ -1057,7 +1065,7 @@
 		if (line >= 0 && DOC_VALID(doc))
 		{
 			ret = navqueue_goto_line(old_doc, doc, line);
-			if (ret && ui_is_keyval_enter_or_return(keyval))
+			if (ret && focus_editor)
 				gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
 		}
 		else if (line < 0 && string != NULL)
@@ -1073,7 +1081,7 @@
 				if (doc != NULL)
 				{
 					ret = (line < 0) ? TRUE : navqueue_goto_line(old_doc, doc, line);
-					if (ret && ui_is_keyval_enter_or_return(keyval))
+					if (ret && focus_editor)
 						gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci));
 				}
 			}
@@ -1089,22 +1097,24 @@
 											 gpointer user_data)
 {
 	/* user_data might be NULL, GPOINTER_TO_INT returns 0 if called with NULL */
+	gboolean double_click = event->type == GDK_2BUTTON_PRESS;
 
-	if (event->button == 1)
+	if (event->button == 1 && (event->type == GDK_BUTTON_RELEASE || double_click))
 	{
 		switch (GPOINTER_TO_INT(user_data))
 		{
 			case MSG_COMPILER:
-			{	/* single click in the compiler treeview */
-				msgwin_goto_compiler_file_line(0);
+			{	/* mouse click in the compiler treeview */
+				msgwin_goto_compiler_file_line(double_click);
 				break;
 			}
 			case MSG_MESSAGE:
-			{	/* single click in the message treeview (results of 'Find usage') */
-				msgwin_goto_messages_file_line(0);
+			{	/* mouse click in the message treeview (results of 'Find usage') */
+				msgwin_goto_messages_file_line(double_click);
 				break;
 			}
 		}
+		return double_click;	/* TRUE prevents message window re-focusing */
 	}
 
 	if (event->button == 3)

Modified: trunk/src/msgwindow.h
===================================================================
--- trunk/src/msgwindow.h	2011-08-06 18:34:14 UTC (rev 5886)
+++ trunk/src/msgwindow.h	2011-08-13 20:44:39 UTC (rev 5887)
@@ -96,11 +96,11 @@
 
 void msgwin_menu_add_common_items(GtkMenu *menu);
 
-gboolean msgwin_goto_compiler_file_line(guint keyval);
+gboolean msgwin_goto_compiler_file_line(gboolean focus_editor);
 
 void msgwin_parse_compiler_error_line(const gchar *string, const gchar *dir,
 									  gchar **filename, gint *line);
 
-gboolean msgwin_goto_messages_file_line(guint keyval);
+gboolean msgwin_goto_messages_file_line(gboolean focus_editor);
 
 #endif

Modified: trunk/src/ui_utils.c
===================================================================
--- trunk/src/ui_utils.c	2011-08-06 18:34:14 UTC (rev 5886)
+++ trunk/src/ui_utils.c	2011-08-13 20:44:39 UTC (rev 5887)
@@ -1619,7 +1619,7 @@
 	while (TRUE)
 	{
 		gtk_tree_selection_select_iter(treesel, &iter);
-		if (cb(0))
+		if (cb(FALSE))
 			break;	/* found next message */
 
 		if (! tree_model_iter_get_next(model, &iter, down))

Modified: trunk/src/ui_utils.h
===================================================================
--- trunk/src/ui_utils.h	2011-08-06 18:34:14 UTC (rev 5886)
+++ trunk/src/ui_utils.h	2011-08-13 20:44:39 UTC (rev 5887)
@@ -302,7 +302,7 @@
 void ui_update_tab_status(GeanyDocument *doc);
 
 
-typedef gboolean TVMatchCallback(guint);
+typedef gboolean TVMatchCallback(gboolean);
 
 gboolean ui_tree_view_find_next(GtkTreeView *treeview, TVMatchCallback cb);
 


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



More information about the Commits mailing list