Coying navigation history when opening new tabs

Ricardo Fernández Pascual <[email protected]>
Newsgroups gmane.comp.web.galeon.devel
Message-ID <[email protected]>
   Why don't we copy the navigation history when creating new tabs? I
have implemented it and it seems to work ok, but I think there were some
issues with it that I don't remember....

   What were those issues, if any? Does this patch work for you too?

   I'll commit it unless you tell me that it's broken in some way.



-- 
Ricardo Fernández Pascual
[email protected]
Murcia. España.
copy_navigation_history.diff (text/plain, 8.2 KB)
? copy_navigation_history.diff
? stamp-h1
? bookmarks/default-bookmarks.xbel
? doc/C/galeon-C.omf.out
? src/galeon-gdb
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/galeon/ChangeLog,v
retrieving revision 1.3534
diff -u -r1.3534 ChangeLog
--- ChangeLog	20 Mar 2003 14:31:47 -0000	1.3534
+++ ChangeLog	21 Mar 2003 19:34:45 -0000
@@ -1,3 +1,14 @@
+2003-03-21  Ricardo Fernández Pascual  <[email protected]>
+
+	* embed/galeon-embed.c
+	* embed/galeon-embed.h: Expanded the interface of
+	galeon_embed_shistory_copy.
+	* mozilla/GaleonWrapper.h
+	* mozilla/GaleonWrapper.cpp
+	* mozilla/mozilla-embed.cpp: Updated acordingly.
+	* src/galeon-shell.c: Copy the navigation history when opening a
+	new tab (for example, with middle click).
+
 2003-03-20  Tommi Komulainen  <[email protected]>
 
 	* ui/galeon-ui.xml.in: "Bookmarks Toolbar*s*", it affects them all.
Index: embed/galeon-embed.c
===================================================================
RCS file: /cvs/gnome/galeon/embed/galeon-embed.c,v
retrieving revision 1.30
diff -u -r1.30 galeon-embed.c
--- embed/galeon-embed.c	9 Feb 2003 21:30:20 -0000	1.30
+++ embed/galeon-embed.c	21 Mar 2003 19:34:47 -0000
@@ -550,10 +550,13 @@
 
 gboolean
 galeon_embed_shistory_copy (GaleonEmbed *source,
-                            GaleonEmbed *dest)
+                            GaleonEmbed *dest,
+			    gboolean back_history,
+			    gboolean forward_history,
+			    gboolean set_current)
 {
 	GaleonEmbedClass *klass = GALEON_EMBED_GET_CLASS (source);
-        return klass->shistory_copy (source, dest);
+        return klass->shistory_copy (source, dest, back_history, forward_history, set_current);
 }
 
 gresult
Index: embed/galeon-embed.h
===================================================================
RCS file: /cvs/gnome/galeon/embed/galeon-embed.h,v
retrieving revision 1.31
diff -u -r1.31 galeon-embed.h
--- embed/galeon-embed.h	9 Feb 2003 21:30:20 -0000	1.31
+++ embed/galeon-embed.h	21 Mar 2003 19:34:48 -0000
@@ -273,8 +273,11 @@
 				            int *pos);
 	gresult   (* shistory_go_nth)      (GaleonEmbed *embed, 
 					    int nth);
-	gboolean  (* shistory_copy)        (GaleonEmbed *source,
-				            GaleonEmbed *dest);
+	gboolean  (* shistory_copy)	   (GaleonEmbed *source,
+					    GaleonEmbed *dest,
+					    gboolean back_history,
+					    gboolean forward_history,
+					    gboolean set_current);
 	gresult   (* scroll)               (GaleonEmbed *embed, 
 		  			    EmbedScrollDirection direction);
 	gresult	  (* fine_scroll)	   (GaleonEmbed *embed, 
@@ -405,8 +408,11 @@
 gresult       galeon_embed_shistory_go_nth      (GaleonEmbed *embed, 
 						 int nth);
 
-gboolean      galeon_embed_shistory_copy        (GaleonEmbed *source,
-				                 GaleonEmbed *dest);
+gboolean      galeon_embed_shistory_copy	(GaleonEmbed *source,
+						 GaleonEmbed *dest,
+						 gboolean back_history,
+						 gboolean forward_history,
+						 gboolean set_current);
 
 /* Utils */
 
Index: mozilla/GaleonWrapper.cpp
===================================================================
RCS file: /cvs/gnome/galeon/mozilla/GaleonWrapper.cpp,v
retrieving revision 1.20
diff -u -r1.20 GaleonWrapper.cpp
--- mozilla/GaleonWrapper.cpp	17 Mar 2003 23:28:26 -0000	1.20
+++ mozilla/GaleonWrapper.cpp	21 Mar 2003 19:34:50 -0000
@@ -674,46 +674,36 @@
 	return NS_OK;
 }
 
-nsresult  GaleonWrapper::CopyHistoryTo (GaleonWrapper *dest)
+nsresult  GaleonWrapper::CopyHistoryTo (GaleonWrapper *dest, 
+					PRBool back_history, 
+					PRBool forward_history, 
+					PRBool set_current)
 {
 	nsresult result;
-	int count,index;
-
-	nsCOMPtr<nsIDocShell> DocShell;
-	result = GetDocShell (getter_AddRefs(DocShell));
-	if (NS_FAILED(result) || !DocShell) return NS_ERROR_FAILURE;
-
-	nsCOMPtr<nsIWebNavigation> wn_src = do_QueryInterface (DocShell,
-							       &result);
-	if (!wn_src) return NS_ERROR_FAILURE;
+	PRInt32 count, index;
 	
 	nsCOMPtr<nsISHistory> h_src;
-	result = wn_src->GetSessionHistory (getter_AddRefs (h_src));
-	if (!NS_SUCCEEDED(result) || (!h_src)) return NS_ERROR_FAILURE;
+	result = GetSHistory (getter_AddRefs(h_src));
+	if (NS_FAILED(result) || !h_src) return NS_ERROR_FAILURE;
+
+	h_src->GetCount (&count);
+	h_src->GetIndex (&index);
 
-	nsCOMPtr<nsIDocShell> destDocShell;
-	result = dest->GetDocShell (getter_AddRefs(destDocShell));
-	if (NS_FAILED(result) || !DocShell) return NS_ERROR_FAILURE;
-
-	nsCOMPtr<nsIWebNavigation> wn_dest = do_QueryInterface (destDocShell,
-								&result);
-	if (!wn_dest) return NS_ERROR_FAILURE;
-	
 	nsCOMPtr<nsISHistory> h_dest;
-	result = wn_dest->GetSessionHistory (getter_AddRefs (h_dest));
+	result = dest->GetSHistory (getter_AddRefs (h_dest));
 	if (!NS_SUCCEEDED (result) || (!h_dest)) return NS_ERROR_FAILURE;
 
 	nsCOMPtr<nsISHistoryInternal> hi_dest = do_QueryInterface (h_dest);
 	if (!hi_dest) return NS_ERROR_FAILURE;
 
-	h_src->GetCount (&count);
-	h_src->GetIndex (&index);
-
 	if (count) {
 		nsCOMPtr<nsIHistoryEntry> he;
 		nsCOMPtr<nsISHEntry> she;
 
-		for (PRInt32 i = 0; i < count; i++) {
+		for (PRInt32 i = (back_history ? 0 : index + 1); 
+		     i < (forward_history ? count : index + 1);
+		     i++) 
+		{
 
 			result = h_src->GetEntryAtIndex (i, PR_FALSE,
 							 getter_AddRefs (he));
@@ -727,9 +717,18 @@
 			if (!NS_SUCCEEDED(result) || (!she))
 				return NS_ERROR_FAILURE;
 		}
-
-		result = wn_dest->GotoIndex(index);
-		if (!NS_SUCCEEDED(result)) return NS_ERROR_FAILURE;
+		
+		if (set_current)
+		{
+			nsCOMPtr<nsIDocShell> destDocShell;
+			result = dest->GetDocShell (getter_AddRefs(destDocShell));
+			if (NS_FAILED(result) || !destDocShell) return NS_ERROR_FAILURE;
+		
+			nsCOMPtr<nsIWebNavigation> wn_dest = do_QueryInterface (destDocShell, &result);
+			
+			result = wn_dest->GotoIndex(index);
+			if (!NS_SUCCEEDED(result)) return NS_ERROR_FAILURE;
+		}
 	}
 
 	return NS_OK;
Index: mozilla/GaleonWrapper.h
===================================================================
RCS file: /cvs/gnome/galeon/mozilla/GaleonWrapper.h,v
retrieving revision 1.10
diff -u -r1.10 GaleonWrapper.h
--- mozilla/GaleonWrapper.h	12 Mar 2003 11:59:23 -0000	1.10
+++ mozilla/GaleonWrapper.h	21 Mar 2003 19:34:51 -0000
@@ -87,7 +87,7 @@
 	nsresult GetSHTitleAtIndex (PRInt32 index, PRUnichar **title);
 	nsresult GetSHUrlAtIndex (PRInt32 index, nsCString &url);
 
-	nsresult CopyHistoryTo (GaleonWrapper *embed);
+	nsresult CopyHistoryTo (GaleonWrapper *embed, PRBool back_history, PRBool forward_history, PRBool set_current);
 
 	nsresult GoToHistoryIndex (PRInt16 index);
 
Index: mozilla/mozilla-embed.cpp
===================================================================
RCS file: /cvs/gnome/galeon/mozilla/mozilla-embed.cpp,v
retrieving revision 1.62
diff -u -r1.62 mozilla-embed.cpp
--- mozilla/mozilla-embed.cpp	12 Mar 2003 11:59:23 -0000	1.62
+++ mozilla/mozilla-embed.cpp	21 Mar 2003 19:34:53 -0000
@@ -153,7 +153,10 @@
                       int nth);
 static gboolean
 impl_shistory_copy (GaleonEmbed *source,
-                    GaleonEmbed *dest);
+		    GaleonEmbed *dest,
+		    gboolean back_history,
+		    gboolean forward_history,
+		    gboolean set_current);
 static gresult
 impl_scroll (GaleonEmbed *embed, 
              EmbedScrollDirection direction);
@@ -1041,7 +1044,10 @@
 
 static gboolean
 impl_shistory_copy (GaleonEmbed *source,
-                    GaleonEmbed *dest)
+		    GaleonEmbed *dest,
+		    gboolean back_history,
+		    gboolean forward_history,
+		    gboolean set_current)
 {
 	nsresult rv;
 	GaleonWrapper *s_wrapper;
@@ -1053,7 +1059,7 @@
 	d_wrapper = MOZILLA_EMBED(dest)->priv->wrapper;
 	g_return_val_if_fail (d_wrapper != NULL, G_FAILED);
 
-	rv = s_wrapper->CopyHistoryTo (d_wrapper);
+	rv = s_wrapper->CopyHistoryTo (d_wrapper, back_history, forward_history, set_current);
 
 	return NS_SUCCEEDED(rv) ? G_OK : G_FAILED;
 }
Index: src/galeon-shell.c
===================================================================
RCS file: /cvs/gnome/galeon/src/galeon-shell.c,v
retrieving revision 1.74
diff -u -r1.74 galeon-shell.c
--- src/galeon-shell.c	10 Mar 2003 19:11:34 -0000	1.74
+++ src/galeon-shell.c	21 Mar 2003 19:34:57 -0000
@@ -507,6 +507,11 @@
 		galeon_embed_load_url (embed, url);
 	}
 
+	if (embed && previous_embed)
+	{
+		galeon_embed_shistory_copy (previous_embed, embed, TRUE, FALSE, FALSE);
+	}
+
         return tab;
 }
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.