Re: Some Autocompletion window patches

Crispin Flowerday <[email protected]>
Newsgroups gmane.comp.web.galeon.devel
Message-ID <1057510177.23844.8.camel@drno>
On Fri, 2003-07-04 at 22:34, Tommi Komulainen wrote:
> On 2003-07-02 22:56 +0100, Crispin Flowerday <[email protected]> wrote:
> > 
> > Attached is a patch to fix the signal leak, and one to add the
> > CTRL+Enter into the autocompletion box. For the CTRL+Enter one, you also
> > need my previous patch for CTRL+Enter in the location bar.
> 
> Actually, applying the patch is giving two rejects because of the
> previous patch.  It's trivial, though, but you might want to rediff.
> 
> A bigger issue is, is it really working for you?  Every time I use
> cursor keys to move around in the autocompletion window and then hit
> Ctrl, the focus seems to move away from the window, back to the location
> entry.  Kind of renders the patch useless when it's impossible to press
> Ctrl-Enter while still in the autocompletion window ;)

Attached are the fixed versions of the autocompletion CTRL+Enter and
signal leak patches. Also there is one to fix ctrl+enter with a bookmark
nickname in the location entry bar.

Interestingly it seems that one of the signals that the autocompletion
window connected to isn't actually needed. We were attaching to the
location entry text box as well, however as the autocompletion window
does a grab of the keyboard, it isn't needed.

Also I have fixed my crash dialog patch.

You can see all the patches I have posted here that arn't in the CVS at
http://patches.theflowerdays.com .

Cheers

Crispin
galeon_autocomplete_ctrl_enter.diff (text/x-patch, 4.3 KB)
diff -u utils/galeon-autocompletion-window.c utils/galeon-autocompletion-window.c
--- utils/galeon-autocompletion-window.c	3 Jul 2003 22:14:28 -0000
+++ utils/galeon-autocompletion-window.c	6 Jul 2003 14:24:24 -0000
@@ -98,7 +98,7 @@
 								 GdkEventKey *event,
 								 GaleonAutocompletionWindow *aw);
 static gboolean	galeon_autocompletion_window_key_press_hack	(GaleonAutocompletionWindow *aw, 
-								 guint keyval);
+								 GdkEventKey *event);
 static void 	hack_tree_view_move_selection 			(GtkTreeView *tv, int dir);
 static void	galeon_autocompletion_window_event_after_cb	(GtkWidget *wid, GdkEvent *event,
 								 GaleonAutocompletionWindow *aw);
@@ -137,8 +137,8 @@
 		G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP,
                 G_STRUCT_OFFSET (GaleonAutocompletionWindowClass, url_activated), 
 		NULL, NULL, 
-		galeon_marshal_VOID__STRING,
-		G_TYPE_NONE, 1, G_TYPE_STRING);
+		galeon_marshal_VOID__STRING_INT,
+		G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
 
 	GaleonAutocompletionWindowSignals[GALEON_AUTOCOMPLETION_WINDOW_HIDDEN] = g_signal_new (
 		"hidden", G_OBJECT_CLASS_TYPE (klass),  
@@ -644,7 +644,7 @@
 	    || ((event->keyval == GDK_space || event->keyval == GDK_Return)
 		&& p->selected))
 	{
-		return galeon_autocompletion_window_key_press_hack (aw, event->keyval);
+		return galeon_autocompletion_window_key_press_hack (aw, event);
 	}
 	else
 	{
@@ -673,10 +673,11 @@
 }
 
 static gboolean
-galeon_autocompletion_window_key_press_hack (GaleonAutocompletionWindow *aw, guint keyval)
+galeon_autocompletion_window_key_press_hack (GaleonAutocompletionWindow *aw, 
+					     GdkEventKey *event)
 {
 	GaleonAutocompletionWindowPrivate *p = aw->priv;
-	switch (keyval)
+	switch (event->keyval)
 	{
 	case GDK_Up:
 		hack_tree_view_move_selection (p->tree_view, -1);
@@ -694,8 +695,13 @@
 	case GDK_space:
 		if (p->selected)
 		{
+			gboolean new_tab_or_window = FALSE;
+			if ( event->state & GDK_CONTROL_MASK )
+				new_tab_or_window = TRUE;
+
 			g_signal_emit (aw, GaleonAutocompletionWindowSignals
-				       [GALEON_AUTOCOMPLETION_WINDOW_URL_ACTIVATED], 0, p->selected->data);
+				       [GALEON_AUTOCOMPLETION_WINDOW_URL_ACTIVATED], 0, 
+				       p->selected->data, new_tab_or_window);
 		}
 		break;
 	default:
@@ -794,7 +800,8 @@
 		if (p->selected)
 		{
 			g_signal_emit (aw, GaleonAutocompletionWindowSignals
-				       [GALEON_AUTOCOMPLETION_WINDOW_URL_ACTIVATED], 0, p->selected->data);
+				       [GALEON_AUTOCOMPLETION_WINDOW_URL_ACTIVATED], 0, 
+				       p->selected->data, FALSE);
 		}
 	}
 }
only in patch2:
unchanged:
--- utils/galeon-autocompletion-window.h	29 Sep 2002 20:07:49 -0000	1.2
+++ utils/galeon-autocompletion-window.h	6 Jul 2003 14:24:24 -0000
@@ -55,7 +55,8 @@
 	/* signals */
 	void		(*hidden)			(GaleonAutocompletionWindow *aw);
 	void		(*url_activated)		(GaleonAutocompletionWindow *aw, 
-							 const gchar *item);
+							 const gchar *item,
+							 gboolean new_tab_or_window);
 
 };
 
only in patch2:
unchanged:
--- utils/location-entry.c	6 Jul 2003 07:41:09 -0000	1.16
+++ utils/location-entry.c	6 Jul 2003 14:24:25 -0000
@@ -77,6 +77,7 @@
 static void		galeon_location_entry_autocompletion_window_url_activated_cb
 /***/								(GaleonAutocompletionWindow *aw, 
 								 const gchar *url, 
+								 gboolean new_tab_or_window,
 								 GaleonLocationEntry *w);
 static void		galeon_location_entry_list_event_after_cb (GtkWidget *list,
 								   GdkEvent *event, 
@@ -502,6 +503,11 @@
                         //real_set_location (w, embed->location);
                 }
                 break;
+	case GDK_Control_L:
+	case GDK_Control_R:
+		/* Ignore these keys so that CTRL+Enter works properly in
+		 * the autocompletion dialog box */
+		break;
         default:
 		w->priv->editing = TRUE;
 		galeon_location_entry_autocompletion_unselect_alternatives (w);
@@ -626,7 +632,9 @@
 
 static void
 galeon_location_entry_autocompletion_window_url_activated_cb (GaleonAutocompletionWindow *aw, 
-							      const gchar *url, GaleonLocationEntry *w)
+							      const gchar *url, 
+							      gboolean new_tab_or_window,
+							      GaleonLocationEntry *w)
 {
 	real_set_location (w, url);
 
@@ -634,7 +642,7 @@
 
 	galeon_location_entry_autocompletion_hide_alternatives (w);
 
-	emit_activated_signal (w, url, FALSE);
+	emit_activated_signal (w, url, new_tab_or_window);
 }
 
 static void
galeon_autocomplete_signal_leak.diff (text/x-patch, 1.6 KB)
diff -u -r1.11 galeon-autocompletion-window.c
--- utils/galeon-autocompletion-window.c	2 Oct 2002 15:06:48 -0000	1.11
+++ utils/galeon-autocompletion-window.c	3 Jul 2003 22:14:28 -0000
@@ -165,6 +165,16 @@
 	gtk_tree_selection_set_mode (s, GTK_SELECTION_MULTIPLE);
 	
 	g_signal_connect (s, "changed", G_CALLBACK (galeon_autocompletion_window_selection_changed_cb), aw);
+
+	g_signal_connect (p->window, "button-press-event", 
+			  G_CALLBACK (galeon_autocompletion_window_button_press_event_cb),
+			  aw);
+	g_signal_connect (p->window, "key-press-event",
+			  G_CALLBACK (galeon_autocompletion_window_key_press_cb),
+			  aw);
+	g_signal_connect (p->tree_view, "event-after", 
+			  G_CALLBACK (galeon_autocompletion_window_event_after_cb),
+			  aw);
 }
 
 static void
@@ -580,21 +590,8 @@
 				  GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK |
 				  GDK_BUTTON_RELEASE_MASK,
 				  NULL, NULL, GDK_CURRENT_TIME);
-		gdk_keyboard_grab (p->parent->window, TRUE, GDK_CURRENT_TIME);\
+		gdk_keyboard_grab (p->parent->window, TRUE, GDK_CURRENT_TIME);
 		gtk_grab_add (p->window);
-		
-		g_signal_connect (p->window, "button-press-event", 
-				  G_CALLBACK (galeon_autocompletion_window_button_press_event_cb),
-				  aw);
-		g_signal_connect (p->window, "key-press-event",
-				  G_CALLBACK (galeon_autocompletion_window_key_press_cb),
-				  aw);
-		g_signal_connect (p->parent, "key-press-event",
-				  G_CALLBACK (galeon_autocompletion_window_key_press_cb),
-				  aw);
-		g_signal_connect (p->tree_view, "event-after", 
-				  G_CALLBACK (galeon_autocompletion_window_event_after_cb),
-				  aw);
 		p->shown = TRUE;
 	}
galeon_location_nick_ctrl_enter.diff (text/x-patch, 1.2 KB)
Index: src/toolbar.c
===================================================================
RCS file: /cvs/gnome/galeon/src/toolbar.c,v
retrieving revision 1.246
diff -u -r1.246 toolbar.c
--- src/toolbar.c	3 Jul 2003 20:42:55 -0000	1.246
+++ src/toolbar.c	6 Jul 2003 15:20:13 -0000
@@ -223,15 +223,30 @@
 toolbar_location_url_activate_cb (GaleonLocationEntry *entry, const gchar *url,
                                   gboolean new_tab_or_window, GaleonWindow *window)
 {
-	if (!new_tab_or_window) 
+	GbBookmarkSet *set;
+	gchar *real_url;
+	GaleonTab *tab;
+
+	if (!new_tab_or_window)
+	{
+		/* galeon_window_load_url handles bookmark nicks */
 		galeon_window_load_url (window, url);
-	else
+		return;
+	}
+
+	set = galeon_shell_get_bookmark_set (galeon_shell);
+	if (set)
 	{
-		/* Open the link in a new tab (or window) */
-		GaleonTab *tab = galeon_window_get_active_tab (window);
-		
-		galeon_shell_new_tab (galeon_shell, window, tab, url, 0);
+		real_url = gb_bookmark_set_get_url_by_nick_and_args (set, url);
+		if (real_url) url = real_url;
 	}
+
+	/* Open the link in a new tab (or window) */
+	tab = galeon_window_get_active_tab (window);
+
+	galeon_shell_new_tab (galeon_shell, window, tab, url, 0);
+	
+	if (real_url) g_free (real_url);
 }
 
 static void
galeon_crash_dialog_fix.diff (text/x-patch, 3.7 KB)
Index: src/session.c
===================================================================
RCS file: /cvs/gnome/galeon/src/session.c,v
retrieving revision 1.153
diff -u -r1.153 session.c
--- src/session.c	19 Jan 2003 16:19:13 -0000	1.153
+++ src/session.c	3 Jul 2003 22:16:14 -0000
@@ -254,9 +254,11 @@
  *
  * Resume a crashed session when necessary (interactive)
  * 
- * Return value: return false if no window  has been opened
+ * Return value: returns SESSION_ABORT   if the user wants to abort starting galeon
+ *                       SESSION_RESUMED if a session has been resumed
+ *                       SESSION_OK      if no session was resumed
  **/
-gboolean
+SessionResumeType
 session_autoresume (Session *session)
 {
 	char *saved_session;
@@ -266,13 +268,13 @@
 
 	if (g_file_test (saved_session, G_FILE_TEST_EXISTS))
 	{
-		/* we want to exit now, so dont open windows
-		 * but return like if we did . Also we need
-		 * to not remove the crashed session. */
+		/* we want to exit now, so tell our caller that the
+		 * user wants to abort, but dont remove the crashed
+		 * sesion. */
 		if (!crashed_resume_dialog (session))
 		{
 			session->priv->dont_remove_crashed = TRUE;
-			return TRUE;
+			return SESSION_ABORT;
 		}
 			
 		loaded = TRUE;
@@ -291,8 +293,8 @@
 	
 	g_free (saved_session);
 
-	/* return false if no window has been opened */
-	return (session->priv->windows != NULL);
+	/* return SESSION_RESUMED, if a window was opened, else SESSION_OK */
+	return (session->priv->windows != NULL) ? SESSION_RESUMED : SESSION_OK;
 }
 
 static void
Index: src/session.h
===================================================================
RCS file: /cvs/gnome/galeon/src/session.h,v
retrieving revision 1.25
diff -u -r1.25 session.h
--- src/session.h	19 Jan 2003 16:19:13 -0000	1.25
+++ src/session.h	3 Jul 2003 22:16:14 -0000
@@ -41,6 +41,12 @@
 
 typedef struct SessionPrivate SessionPrivate;
 
+typedef enum {
+   SESSION_OK,
+   SESSION_RESUMED,
+   SESSION_ABORT
+} SessionResumeType;
+
 struct Session
 {
         GObject parent;
@@ -70,7 +76,7 @@
 void	      session_save     		(Session *session,
 					 const char *filename);
 
-gboolean      session_autoresume   	(Session *session);
+SessionResumeType session_autoresume   	(Session *session);
 
 const GList  *session_get_windows     	(Session *session);
 
Index: src/galeon-automation.c
===================================================================
RCS file: /cvs/gnome/galeon/src/galeon-automation.c,v
retrieving revision 1.19
diff -u -r1.19 galeon-automation.c
--- src/galeon-automation.c	1 May 2003 21:27:40 -0000	1.19
+++ src/galeon-automation.c	3 Jul 2003 22:16:14 -0000
@@ -62,7 +62,7 @@
 	guint open_in_new_tab : 1;
 } GaleonAutomationLoadurlData;
 
-GSList *postponed_loadurls = NULL;
+static GSList *postponed_loadurls = NULL;
 static gboolean initialized = FALSE;
 
 static BonoboObject *
@@ -168,11 +168,25 @@
 	/* no window open, let's try to autoresume */
 	if (session_get_windows (session) == NULL)
 	{
-		gboolean res;
+		SessionResumeType res;
 		res = session_autoresume (session);
+
+		/* Don't load any windows, the use wants to abort this
+		 * instance */
+		if ( res == SESSION_ABORT ) {
+			GSList * iterator;
+			for( iterator = postponed_loadurls ; iterator ; iterator = iterator->next) {
+				GaleonAutomationLoadurlData *data = iterator->data;
+				g_free (data->url);
+				g_free (data);
+			}
+			g_slist_free (postponed_loadurls);
+			return;
+		}
+		
 		/* no need to open the homepage,
 		 * we did already open session windows */
-		if (res && postponed_loadurls) {
+		if (res == SESSION_RESUMED && postponed_loadurls) {
 			GSList *last = g_slist_last (postponed_loadurls);
 			GaleonAutomationLoadurlData *data = last->data;
 			if (data->url == NULL || *data->url == 0) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.