incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [19/34] wp7 commit: Fixed CB-459, now back button integrated
Date Mon, 09 Apr 2012 22:40:30 GMT
Fixed CB-459, now back button integrated


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/commit/8019b10d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/tree/8019b10d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/diff/8019b10d

Branch: refs/heads/master
Commit: 8019b10dc503890372720d4a77c0b9bef28f16a1
Parents: 6f4beaa
Author: filmaj <maj.fil@gmail.com>
Authored: Sun Apr 8 19:22:30 2012 -0700
Committer: filmaj <maj.fil@gmail.com>
Committed: Sun Apr 8 19:22:30 2012 -0700

----------------------------------------------------------------------
 framework/CordovaView.xaml.cs |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-wp7/blob/8019b10d/framework/CordovaView.xaml.cs
----------------------------------------------------------------------
diff --git a/framework/CordovaView.xaml.cs b/framework/CordovaView.xaml.cs
index 0ca9bd2..215db1f 100644
--- a/framework/CordovaView.xaml.cs
+++ b/framework/CordovaView.xaml.cs
@@ -50,8 +50,19 @@ namespace WP7CordovaClassLib
         /// Prevents data clearing during page transitions.
         /// </summary>
         private bool IsBrowserInitialized = false;
+        
+        /// <summary>
+        /// Set when the user attaches a back button handler inside the WebBrowser
+        /// </summary>
         private bool OverrideBackButton = false;
 
+        /// <summary>
+        /// Used for keeping track of our history
+        /// </summary>
+        private Stack<Uri> history = new Stack<Uri>();
+        private bool IsBackButtonPressed = false;
+
+
         private static string AppRoot = "/app/";
 
 
@@ -311,9 +322,20 @@ namespace WP7CordovaClassLib
                     CordovaBrowser.InvokeScript("CordovaCommandResult", new string[] { "backbutton"
});
                     e.Cancel = true;
                 }
-                catch (Exception)
+                catch (Exception ex)
                 {
-
+                    Console.WriteLine("Exception while invoking backbutton into cordova view:
" + ex.Message);
+                }
+            }
+            else
+            {
+                if (history.Count > 1)
+                {
+                    history.Pop();
+                    Uri next = history.Peek();
+                    IsBackButtonPressed = true;
+                    CordovaBrowser.Navigate(next);
+                    e.Cancel = true;
                 }
             }
         }
@@ -337,6 +359,15 @@ namespace WP7CordovaClassLib
 
         void GapBrowser_Navigating(object sender, NavigatingEventArgs e)
         {
+            if (!IsBackButtonPressed)
+            {
+                history.Push(e.Uri);
+            }
+            else
+            {
+                IsBackButtonPressed = false;
+            }
+
             Debug.WriteLine("GapBrowser_Navigating to :: " + e.Uri.ToString());
             // TODO: tell any running plugins to stop doing what they are doing.
             // TODO: check whitelist / blacklist


Mime
View raw message