EchoTracker
changeset 9:e96d696e0bb3
Wrap the Javascript interface methods.
| author | François-Denis Gonthier <fdgonthier@kryptiva.com> |
|---|---|
| date | Wed Mar 24 14:47:50 2010 -0400 (2 years ago) |
| parents | a9bb7d37d5b2 |
| children | 87d2747b516f |
| files | EchoTracker/EtHtmlView.cs EchoTracker/EtJavascript.cs |
line diff
1.1 --- a/EchoTracker/EtHtmlView.cs Wed Mar 24 13:45:23 2010 -0400
1.2 +++ b/EchoTracker/EtHtmlView.cs Wed Mar 24 14:47:50 2010 -0400
1.3 @@ -31,16 +31,95 @@
1.4 // Still not sure about this...
1.5 public class EtHtmlMailItemViewList
1.6 {
1.7 - private EtHtmlView htmlView;
1.8 + private IEtViewInterface scripts;
1.9
1.10 public void Add(string objType, ulong objID, DbEmailItem etMailItem)
1.11 {
1.12 - htmlView.CallJS3("AddMailItemMatch", objType, objID, (IEtMailItem)etMailItem);
1.13 + scripts.AddMailItemMatch(objType, objID, (IEtMailItem)etMailItem);
1.14 }
1.15
1.16 - public EtHtmlMailItemViewList(EtHtmlView hv)
1.17 + public EtHtmlMailItemViewList(IEtViewInterface s)
1.18 {
1.19 - htmlView = hv;
1.20 + scripts = s;
1.21 + }
1.22 + }
1.23 +
1.24 + public class EtHtmlViewInterface : IEtViewInterface
1.25 + {
1.26 + #region IEtViewInterface Members
1.27 +
1.28 + public void ChangeView(string viewMode)
1.29 + {
1.30 + CallJS1("ChangeView", viewMode);
1.31 + }
1.32 +
1.33 + public void ShowIndexerProgress(int pct, string status)
1.34 + {
1.35 + CallJS2("ShowIndexProgress", pct, status);
1.36 + }
1.37 +
1.38 + public void ShowMailItem(IEtMailUser viewUser)
1.39 + {
1.40 + CallJS1("ShowMailItem", viewUser);
1.41 + }
1.42 +
1.43 + public void AddMailItemMatch(string objType, ulong objID, IEtMailItem obj)
1.44 + {
1.45 + CallJS3("AddMailItemMatch", objType, objID, obj);
1.46 + }
1.47 +
1.48 + #endregion
1.49 +
1.50 + private WebBrowser htmlView;
1.51 +
1.52 + /// <summary>
1.53 + /// Call a JavaScript function with 0 arguments.
1.54 + /// </summary>
1.55 + private void CallJS0(string funcname)
1.56 + {
1.57 + object[] args = new object[0];
1.58 + htmlView.Document.InvokeScript(funcname, args);
1.59 + }
1.60 +
1.61 + /// <summary>
1.62 + /// Call a JavaScript function with 1 arguments.
1.63 + /// </summary>
1.64 + private void CallJS1(string funcname, object arg1)
1.65 + {
1.66 + object[] args = new object[1];
1.67 +
1.68 + args[0] = arg1;
1.69 + htmlView.Document.InvokeScript(funcname, args);
1.70 + }
1.71 +
1.72 + /// <summary>
1.73 + /// Call a JavaScript function with 2 arguments.
1.74 + /// </summary>
1.75 + private void CallJS2(string funcname, object arg1, object arg2)
1.76 + {
1.77 + object[] args = new object[2];
1.78 +
1.79 + args[0] = arg1;
1.80 + args[1] = arg2;
1.81 + htmlView.Document.InvokeScript(funcname, args);
1.82 + }
1.83 +
1.84 + /// <summary>
1.85 + /// Call a JavaScript function with 3 arguments.
1.86 + /// </summary>
1.87 + internal void CallJS3(string funcname, object arg1, object arg2, object arg3)
1.88 + {
1.89 + object[] args = new object[3];
1.90 +
1.91 + args[0] = arg1;
1.92 + args[1] = arg2;
1.93 + args[2] = arg3;
1.94 + htmlView.Document.InvokeScript(funcname, args);
1.95 + }
1.96 +
1.97 + public EtHtmlViewInterface(WebBrowser view)
1.98 + {
1.99 + htmlView = view;
1.100 }
1.101 }
1.102
1.103 @@ -92,66 +171,23 @@
1.104 /// <summary>
1.105 /// The function that can be called on window.external.
1.106 /// </summary>
1.107 - public IEtExternalInterface callbacks;
1.108 + private IEtExternalInterface callbacks;
1.109 +
1.110 + /// <summary>
1.111 + /// </summary>
1.112 + private IEtViewInterface scripts;
1.113
1.114 /// <summary>
1.115 /// The URL to the main.html file.
1.116 /// </summary>
1.117 private string htmlViewUrl;
1.118
1.119 - /// <summary>
1.120 - /// Call a JavaScript function with 0 arguments.
1.121 - /// </summary>
1.122 - /// FIXME: Replace with something more clever.
1.123 - internal void CallJS0(string funcname)
1.124 - {
1.125 - object[] args = new object[0];
1.126 - echoTracker.Document.InvokeScript(funcname, args);
1.127 - }
1.128 -
1.129 - /// <summary>
1.130 - /// Call a JavaScript function with 1 arguments.
1.131 - /// </summary>
1.132 - /// FIXME: Replace with something more clever.
1.133 - internal void CallJS1(string funcname, object arg1)
1.134 - {
1.135 - object[] args = new object[1];
1.136 -
1.137 - args[0] = arg1;
1.138 - echoTracker.Document.InvokeScript(funcname, args);
1.139 - }
1.140 -
1.141 - /// <summary>
1.142 - /// Call a JavaScript function with 2 arguments.
1.143 - /// </summary>
1.144 - /// FIXME: Replace with something more clever.
1.145 - internal void CallJS2(string funcname, object arg1, object arg2)
1.146 - {
1.147 - object[] args = new object[2];
1.148 -
1.149 - args[0] = arg1;
1.150 - args[1] = arg2;
1.151 - echoTracker.Document.InvokeScript(funcname, args);
1.152 - }
1.153 -
1.154 - /// <summary>
1.155 - /// Call a JavaScript function with 3 arguments.
1.156 - /// </summary>
1.157 - /// FIXME: Replace with something more clever.
1.158 - internal void CallJS3(string funcname, object arg1, object arg2, object arg3)
1.159 - {
1.160 - object[] args = new object[3];
1.161 -
1.162 - args[0] = arg1;
1.163 - args[1] = arg2;
1.164 - args[2] = arg3;
1.165 - echoTracker.Document.InvokeScript(funcname, args);
1.166 - }
1.167 -
1.168 public EtHtmlView(IEtExternalInterface cb)
1.169 {
1.170 InitializeComponent();
1.171
1.172 + scripts = new EtHtmlViewInterface(echoTracker);
1.173 +
1.174 // Set the window.external object.
1.175 echoTracker.ObjectForScripting = cb;
1.176
1.177 @@ -169,7 +205,7 @@
1.178 // web browser object.
1.179 if (Mode == EtViewMode.Changing)
1.180 {
1.181 - CallJS1("ChangeView", EtViewModeUtils.ToString(wantedMode));
1.182 + scripts.ChangeView(EtViewModeUtils.ToString(wantedMode));
1.183
1.184 // FIXME: Catch view change problems.
1.185 Debug.Assert(currentMode == wantedMode);
1.186 @@ -221,7 +257,7 @@
1.187 wantedMode = value;
1.188 currentMode = EtViewMode.Changing;
1.189
1.190 - CallJS1("changeView", EtViewModeUtils.ToString(wantedMode));
1.191 + scripts.ChangeView(EtViewModeUtils.ToString(wantedMode));
1.192 }
1.193 }
1.194
1.195 @@ -241,19 +277,19 @@
1.196 /// </summary>
1.197 public void ShowIndexerProgress(int pct, string status)
1.198 {
1.199 - CallJS2("ShowIndexerProgress", pct, status);
1.200 + scripts.ShowIndexerProgress(pct, status);
1.201 }
1.202
1.203 public EtHtmlMailItemViewList ShowMailItem(IEtMailUser viewUser)
1.204 {
1.205 if (Mode != EtViewMode.MailItem) return null;
1.206
1.207 - CallJS1("ShowMailItem", (IEtMailUser)viewUser);
1.208 + scripts.ShowMailItem((IEtMailUser)viewUser);
1.209
1.210 // FIXME: Generate a MailItemViewList which needs to be invalidate
1.211 // once the mailitem changes.
1.212
1.213 - return new EtHtmlMailItemViewList(this);
1.214 + return new EtHtmlMailItemViewList(scripts);
1.215 }
1.216
1.217 #endregion
2.1 --- a/EchoTracker/EtJavascript.cs Wed Mar 24 13:45:23 2010 -0400
2.2 +++ b/EchoTracker/EtJavascript.cs Wed Mar 24 14:47:50 2010 -0400
2.3 @@ -124,6 +124,11 @@
2.4 // Recipients
2.5 }
2.6
2.7 + /// <summary>
2.8 + /// This interface is used for the communication between the Javascript code
2.9 + /// inside the webbrowser object and the Echotracker core. This interface is
2.10 + /// accessable through the window.external object in Javascript.
2.11 + /// </summary>
2.12 public interface IEtExternalInterface
2.13 {
2.14 // Viewer functions
2.15 @@ -147,4 +152,32 @@
2.16 // View changed.
2.17 void ViewChanged(string newView);
2.18 }
2.19 +
2.20 + /// <summary>
2.21 + /// This interface is used for the communication between the view code and the
2.22 + /// Javascript code inside the webbrowser object.
2.23 + /// </summary>
2.24 + public interface IEtViewInterface
2.25 + {
2.26 + /// <summary>
2.27 + /// Start view change inside the view. The change isn't considered completed
2.28 + /// until the Javascripts calls back the view code.
2.29 + /// </summary>
2.30 + void ChangeView(string viewMode);
2.31 +
2.32 + /// <summary>
2.33 + /// Update the indexer progress bar and the associated status text.
2.34 + /// </summary>
2.35 + void ShowIndexerProgress(int pct, string status);
2.36 +
2.37 + /// <summary>
2.38 + ///
2.39 + /// </summary>
2.40 + void ShowMailItem(IEtMailUser viewUser);
2.41 +
2.42 + /// <summary>
2.43 + ///
2.44 + /// </summary>
2.45 + void AddMailItemMatch(string objType, ulong objID, IEtMailItem obj);
2.46 + }
2.47 }