xref: /aoo41x/main/rhino/rhino1_7R3.patch (revision 09c2d57a)
1*09c2d57aSAndre FischerIndex: toolsrc/org/mozilla/javascript/tools/debugger/GuiCallback.java
2*09c2d57aSAndre Fischer===================================================================
3*09c2d57aSAndre Fischer--- toolsrc/org/mozilla/javascript/tools/debugger/GuiCallback.java	(revision 1)
4*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/toolsrc/org/mozilla/javascript/tools/debugger/GuiCallback.java	(working copy)
5*09c2d57aSAndre Fischer@@ -56,6 +56,11 @@
6*09c2d57aSAndre Fischer                         String threadTitle,
7*09c2d57aSAndre Fischer                         String alertMessage);
8*09c2d57aSAndre Fischer
9*09c2d57aSAndre Fischer+	/**
10*09c2d57aSAndre Fischer+	 * Called when the interrupt loop has been exited.
11*09c2d57aSAndre Fischer+	 */
12*09c2d57aSAndre Fischer+	void exitInterrupt();
13*09c2d57aSAndre Fischer+
14*09c2d57aSAndre Fischer     /**
15*09c2d57aSAndre Fischer      * Returns whether the current thread is the GUI's event thread.
16*09c2d57aSAndre Fischer      * This information is required to avoid blocking the event thread
17*09c2d57aSAndre FischerIndex: toolsrc/org/mozilla/javascript/tools/debugger/Main.java
18*09c2d57aSAndre Fischer===================================================================
19*09c2d57aSAndre Fischer--- toolsrc/org/mozilla/javascript/tools/debugger/Main.java	(revision 1)
20*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/toolsrc/org/mozilla/javascript/tools/debugger/Main.java	(working copy)
21*09c2d57aSAndre Fischer@@ -44,6 +44,8 @@
22*09c2d57aSAndre Fischer import java.io.InputStream;
23*09c2d57aSAndre Fischer import java.io.PrintStream;
24*09c2d57aSAndre Fischer
25*09c2d57aSAndre Fischer+import java.net.URL;
26*09c2d57aSAndre Fischer+
27*09c2d57aSAndre Fischer import javax.swing.JFrame;
28*09c2d57aSAndre Fischer
29*09c2d57aSAndre Fischer import org.mozilla.javascript.*;
30*09c2d57aSAndre Fischer@@ -161,7 +163,7 @@
31*09c2d57aSAndre Fischer      * Console window.
32*09c2d57aSAndre Fischer      */
33*09c2d57aSAndre Fischer     public InputStream getIn() {
34*09c2d57aSAndre Fischer-        return debugGui.getConsole().getIn();
35*09c2d57aSAndre Fischer+        return null;//return debugGui.getConsole().getIn();
36*09c2d57aSAndre Fischer     }
37*09c2d57aSAndre Fischer
38*09c2d57aSAndre Fischer     /**
39*09c2d57aSAndre Fischer@@ -169,7 +171,7 @@
40*09c2d57aSAndre Fischer      * Console window.
41*09c2d57aSAndre Fischer      */
42*09c2d57aSAndre Fischer     public PrintStream getOut() {
43*09c2d57aSAndre Fischer-        return debugGui.getConsole().getOut();
44*09c2d57aSAndre Fischer+        return null;//return debugGui.getConsole().getOut();
45*09c2d57aSAndre Fischer     }
46*09c2d57aSAndre Fischer
47*09c2d57aSAndre Fischer     /**
48*09c2d57aSAndre Fischer@@ -177,7 +179,7 @@
49*09c2d57aSAndre Fischer      * Console window.
50*09c2d57aSAndre Fischer      */
51*09c2d57aSAndre Fischer     public PrintStream getErr() {
52*09c2d57aSAndre Fischer-        return debugGui.getConsole().getErr();
53*09c2d57aSAndre Fischer+        return null;//return debugGui.getConsole().getErr();
54*09c2d57aSAndre Fischer     }
55*09c2d57aSAndre Fischer
56*09c2d57aSAndre Fischer     /**
57*09c2d57aSAndre Fischer@@ -437,4 +439,39 @@
58*09c2d57aSAndre Fischer             return scope;
59*09c2d57aSAndre Fischer         }
60*09c2d57aSAndre Fischer     }
61*09c2d57aSAndre Fischer+
62*09c2d57aSAndre Fischer+    // shortcut methods
63*09c2d57aSAndre Fischer+
64*09c2d57aSAndre Fischer+    public void addWindowListener(java.awt.event.WindowListener l) {
65*09c2d57aSAndre Fischer+        debugGui.addWindowListener(l);
66*09c2d57aSAndre Fischer+    }
67*09c2d57aSAndre Fischer+
68*09c2d57aSAndre Fischer+    public void highlighLineInScriptWindow(URL url, int lineNum) {
69*09c2d57aSAndre Fischer+		debugGui.highlighLineInScriptWindow(url, lineNum);
70*09c2d57aSAndre Fischer+	}
71*09c2d57aSAndre Fischer+
72*09c2d57aSAndre Fischer+    public Object runScriptWindow(URL scriptUrl) throws Exception
73*09c2d57aSAndre Fischer+    {
74*09c2d57aSAndre Fischer+		return debugGui.runScriptWindow(scriptUrl);
75*09c2d57aSAndre Fischer+	}
76*09c2d57aSAndre Fischer+
77*09c2d57aSAndre Fischer+    public void openFile(URL scriptUrl, Scriptable scope, Runnable closeCallback) {
78*09c2d57aSAndre Fischer+		debugGui.openFile(scriptUrl, scope, closeCallback);
79*09c2d57aSAndre Fischer+	}
80*09c2d57aSAndre Fischer+
81*09c2d57aSAndre Fischer+    public void toFront() {
82*09c2d57aSAndre Fischer+		debugGui.toFront();
83*09c2d57aSAndre Fischer+	}
84*09c2d57aSAndre Fischer+
85*09c2d57aSAndre Fischer+    public void showScriptWindow(URL url) {
86*09c2d57aSAndre Fischer+		debugGui.showScriptWindow(url);
87*09c2d57aSAndre Fischer+	}
88*09c2d57aSAndre Fischer+
89*09c2d57aSAndre Fischer+    public boolean isModified(URL url) {
90*09c2d57aSAndre Fischer+		return debugGui.isModified(url);
91*09c2d57aSAndre Fischer+	}
92*09c2d57aSAndre Fischer+
93*09c2d57aSAndre Fischer+	public String getText(URL url) {
94*09c2d57aSAndre Fischer+		return debugGui.getText(url);
95*09c2d57aSAndre Fischer+	}
96*09c2d57aSAndre Fischer }
97*09c2d57aSAndre FischerIndex: toolsrc/org/mozilla/javascript/tools/debugger/Dim.java
98*09c2d57aSAndre Fischer===================================================================
99*09c2d57aSAndre Fischer--- toolsrc/org/mozilla/javascript/tools/debugger/Dim.java	(revision 1)
100*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/toolsrc/org/mozilla/javascript/tools/debugger/Dim.java	(working copy)
101*09c2d57aSAndre Fischer@@ -69,6 +69,7 @@
102*09c2d57aSAndre Fischer     private static final int IPROXY_OBJECT_TO_STRING = 5;
103*09c2d57aSAndre Fischer     private static final int IPROXY_OBJECT_PROPERTY = 6;
104*09c2d57aSAndre Fischer     private static final int IPROXY_OBJECT_IDS = 7;
105*09c2d57aSAndre Fischer+    private static final int IPROXY_EVAL_SCRIPT_WITH_RETURN = 8;
106*09c2d57aSAndre Fischer
107*09c2d57aSAndre Fischer     /**
108*09c2d57aSAndre Fischer      * Interface to the debugger GUI.
109*09c2d57aSAndre Fischer@@ -433,7 +434,7 @@
110*09c2d57aSAndre Fischer      */
111*09c2d57aSAndre Fischer     private String getNormalizedUrl(DebuggableScript fnOrScript) {
112*09c2d57aSAndre Fischer         String url = fnOrScript.getSourceName();
113*09c2d57aSAndre Fischer-        if (url == null) { url = "<stdin>"; }
114*09c2d57aSAndre Fischer+        if (url == null) { url = "document"; }
115*09c2d57aSAndre Fischer         else {
116*09c2d57aSAndre Fischer             // Not to produce window for eval from different lines,
117*09c2d57aSAndre Fischer             // strip line numbers, i.e. replace all #[0-9]+\(eval\) by
118*09c2d57aSAndre Fischer@@ -622,6 +623,17 @@
119*09c2d57aSAndre Fischer     }
120*09c2d57aSAndre Fischer
121*09c2d57aSAndre Fischer     /**
122*09c2d57aSAndre Fischer+     * Evaluates the given script with scope and return value.
123*09c2d57aSAndre Fischer+     */
124*09c2d57aSAndre Fischer+    public Object evalScriptWithReturn(final String url, final String text, Scriptable scope) {
125*09c2d57aSAndre Fischer+        DimIProxy action = new DimIProxy(this, IPROXY_EVAL_SCRIPT_WITH_RETURN);
126*09c2d57aSAndre Fischer+        action.url = url;
127*09c2d57aSAndre Fischer+        action.text = text;
128*09c2d57aSAndre Fischer+        action.scope = scope;
129*09c2d57aSAndre Fischer+        return contextFactory.call(action);
130*09c2d57aSAndre Fischer+    }
131*09c2d57aSAndre Fischer+
132*09c2d57aSAndre Fischer+    /**
133*09c2d57aSAndre Fischer      * Converts the given script object to a string.
134*09c2d57aSAndre Fischer      */
135*09c2d57aSAndre Fischer     public String objectToString(Object object) {
136*09c2d57aSAndre Fischer@@ -869,6 +881,7 @@
137*09c2d57aSAndre Fischer                 interruptedContextData = null;
138*09c2d57aSAndre Fischer                 eventThreadMonitor.notifyAll();
139*09c2d57aSAndre Fischer             }
140*09c2d57aSAndre Fischer+            callback.exitInterrupt();
141*09c2d57aSAndre Fischer         }
142*09c2d57aSAndre Fischer
143*09c2d57aSAndre Fischer     }
144*09c2d57aSAndre Fischer@@ -966,6 +979,11 @@
145*09c2d57aSAndre Fischer         private Object[] objectArrayResult;
146*09c2d57aSAndre Fischer
147*09c2d57aSAndre Fischer         /**
148*09c2d57aSAndre Fischer+         * The Scriptable as arguments.
149*09c2d57aSAndre Fischer+         */
150*09c2d57aSAndre Fischer+        private Scriptable scope;
151*09c2d57aSAndre Fischer+
152*09c2d57aSAndre Fischer+        /**
153*09c2d57aSAndre Fischer          * Creates a new DimIProxy.
154*09c2d57aSAndre Fischer          */
155*09c2d57aSAndre Fischer         private DimIProxy(Dim dim, int type) {
156*09c2d57aSAndre Fischer@@ -1021,6 +1039,9 @@
157*09c2d57aSAndre Fischer                 objectArrayResult = dim.getObjectIdsImpl(cx, object);
158*09c2d57aSAndre Fischer                 break;
159*09c2d57aSAndre Fischer
160*09c2d57aSAndre Fischer+              case IPROXY_EVAL_SCRIPT_WITH_RETURN:
161*09c2d57aSAndre Fischer+                return cx.evaluateString(this.scope, text, url, 1, null);
162*09c2d57aSAndre Fischer+
163*09c2d57aSAndre Fischer               default:
164*09c2d57aSAndre Fischer                 throw Kit.codeBug();
165*09c2d57aSAndre Fischer             }
166*09c2d57aSAndre FischerIndex: toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java
167*09c2d57aSAndre Fischer===================================================================
168*09c2d57aSAndre Fischer--- toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java	(revision 1)
169*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/toolsrc/org/mozilla/javascript/tools/debugger/SwingGui.java	(working copy)
170*09c2d57aSAndre Fischer@@ -68,6 +68,8 @@
171*09c2d57aSAndre Fischer import java.awt.Toolkit;
172*09c2d57aSAndre Fischer import java.awt.event.*;
173*09c2d57aSAndre Fischer
174*09c2d57aSAndre Fischer+import java.net.URL;
175*09c2d57aSAndre Fischer+
176*09c2d57aSAndre Fischer import java.util.List;
177*09c2d57aSAndre Fischer import java.util.ArrayList;
178*09c2d57aSAndre Fischer import java.util.Arrays;
179*09c2d57aSAndre Fischer@@ -84,6 +86,7 @@
180*09c2d57aSAndre Fischer import java.lang.reflect.Method;
181*09c2d57aSAndre Fischer
182*09c2d57aSAndre Fischer import org.mozilla.javascript.Kit;
183*09c2d57aSAndre Fischer+import org.mozilla.javascript.Scriptable;
184*09c2d57aSAndre Fischer import org.mozilla.javascript.SecurityUtilities;
185*09c2d57aSAndre Fischer
186*09c2d57aSAndre Fischer import org.mozilla.javascript.tools.shell.ConsoleTextArea;
187*09c2d57aSAndre Fischer@@ -178,6 +181,16 @@
188*09c2d57aSAndre Fischer      */
189*09c2d57aSAndre Fischer     private EventQueue awtEventQueue;
190*09c2d57aSAndre Fischer
191*09c2d57aSAndre Fischer+    private boolean sourceEditingEnabled = true;
192*09c2d57aSAndre Fischer+
193*09c2d57aSAndre Fischer+    public boolean isSourceEditingEnabled() {
194*09c2d57aSAndre Fischer+        return sourceEditingEnabled;
195*09c2d57aSAndre Fischer+    }
196*09c2d57aSAndre Fischer+
197*09c2d57aSAndre Fischer+    public void setSourceEditingEnabled(boolean b) {
198*09c2d57aSAndre Fischer+        sourceEditingEnabled = b;
199*09c2d57aSAndre Fischer+    }
200*09c2d57aSAndre Fischer+
201*09c2d57aSAndre Fischer     /**
202*09c2d57aSAndre Fischer      * Creates a new SwingGui.
203*09c2d57aSAndre Fischer      */
204*09c2d57aSAndre Fischer@@ -218,13 +231,13 @@
205*09c2d57aSAndre Fischer         super.setVisible(b);
206*09c2d57aSAndre Fischer         if (b) {
207*09c2d57aSAndre Fischer             // this needs to be done after the window is visible
208*09c2d57aSAndre Fischer-            console.consoleTextArea.requestFocus();
209*09c2d57aSAndre Fischer+            // console.consoleTextArea.requestFocus();
210*09c2d57aSAndre Fischer             context.split.setDividerLocation(0.5);
211*09c2d57aSAndre Fischer             try {
212*09c2d57aSAndre Fischer-                console.setMaximum(true);
213*09c2d57aSAndre Fischer-                console.setSelected(true);
214*09c2d57aSAndre Fischer-                console.show();
215*09c2d57aSAndre Fischer-                console.consoleTextArea.requestFocus();
216*09c2d57aSAndre Fischer+                // console.setMaximum(true);
217*09c2d57aSAndre Fischer+                // console.setSelected(true);
218*09c2d57aSAndre Fischer+                // console.show();
219*09c2d57aSAndre Fischer+                // console.consoleTextArea.requestFocus();
220*09c2d57aSAndre Fischer             } catch (Exception exc) {
221*09c2d57aSAndre Fischer             }
222*09c2d57aSAndre Fischer         }
223*09c2d57aSAndre Fischer@@ -320,7 +333,7 @@
224*09c2d57aSAndre Fischer         desk = new JDesktopPane();
225*09c2d57aSAndre Fischer         desk.setPreferredSize(new Dimension(600, 300));
226*09c2d57aSAndre Fischer         desk.setMinimumSize(new Dimension(150, 50));
227*09c2d57aSAndre Fischer-        desk.add(console = new JSInternalConsole("JavaScript Console"));
228*09c2d57aSAndre Fischer+        // desk.add(console = new JSInternalConsole("JavaScript Console"));
229*09c2d57aSAndre Fischer         context = new ContextWindow(this);
230*09c2d57aSAndre Fischer         context.setPreferredSize(new Dimension(600, 120));
231*09c2d57aSAndre Fischer         context.setMinimumSize(new Dimension(50, 50));
232*09c2d57aSAndre Fischer@@ -540,7 +553,7 @@
233*09c2d57aSAndre Fischer         if (line != -1) {
234*09c2d57aSAndre Fischer             currentWindow = w;
235*09c2d57aSAndre Fischer         }
236*09c2d57aSAndre Fischer-        menubar.addFile(url);
237*09c2d57aSAndre Fischer+        // menubar.addFile(url);
238*09c2d57aSAndre Fischer         w.setVisible(true);
239*09c2d57aSAndre Fischer
240*09c2d57aSAndre Fischer         if (activate) {
241*09c2d57aSAndre Fischer@@ -800,9 +813,17 @@
242*09c2d57aSAndre Fischer             proxy.alertMessage = alertMessage;
243*09c2d57aSAndre Fischer             SwingUtilities.invokeLater(proxy);
244*09c2d57aSAndre Fischer         }
245*09c2d57aSAndre Fischer+        setSourceEditingEnabled(false);
246*09c2d57aSAndre Fischer     }
247*09c2d57aSAndre Fischer
248*09c2d57aSAndre Fischer     /**
249*09c2d57aSAndre Fischer+     * Called when the interrupt loop has been exited.
250*09c2d57aSAndre Fischer+     */
251*09c2d57aSAndre Fischer+    public void exitInterrupt() {
252*09c2d57aSAndre Fischer+        setSourceEditingEnabled(true);
253*09c2d57aSAndre Fischer+    }
254*09c2d57aSAndre Fischer+
255*09c2d57aSAndre Fischer+    /**
256*09c2d57aSAndre Fischer      * Returns whether the current thread is the GUI event thread.
257*09c2d57aSAndre Fischer      */
258*09c2d57aSAndre Fischer     public boolean isGuiEventThread() {
259*09c2d57aSAndre Fischer@@ -879,6 +900,14 @@
260*09c2d57aSAndre Fischer                     new Thread(proxy).start();
261*09c2d57aSAndre Fischer                 }
262*09c2d57aSAndre Fischer             }
263*09c2d57aSAndre Fischer+        } else if (cmd.equals("Run")) {
264*09c2d57aSAndre Fischer+            FileWindow w = (FileWindow)getSelectedFrame();
265*09c2d57aSAndre Fischer+            if (w != null)
266*09c2d57aSAndre Fischer+                w.load();
267*09c2d57aSAndre Fischer+        } else if (cmd.equals("Save")) {
268*09c2d57aSAndre Fischer+            FileWindow w = (FileWindow)getSelectedFrame();
269*09c2d57aSAndre Fischer+            if (w != null)
270*09c2d57aSAndre Fischer+                w.save();
271*09c2d57aSAndre Fischer         } else if (cmd.equals("More Windows...")) {
272*09c2d57aSAndre Fischer             MoreWindows dlg = new MoreWindows(this, fileWindows,
273*09c2d57aSAndre Fischer                                               "Window", "Files");
274*09c2d57aSAndre Fischer@@ -972,6 +1001,120 @@
275*09c2d57aSAndre Fischer             dim.setReturnValue(returnValue);
276*09c2d57aSAndre Fischer         }
277*09c2d57aSAndre Fischer     }
278*09c2d57aSAndre Fischer+
279*09c2d57aSAndre Fischer+    private String getFileName(URL url) {
280*09c2d57aSAndre Fischer+        if (url.getProtocol().startsWith("vnd.sun.star."))
281*09c2d57aSAndre Fischer+            return url.toString();
282*09c2d57aSAndre Fischer+        return url.getPath();
283*09c2d57aSAndre Fischer+    }
284*09c2d57aSAndre Fischer+
285*09c2d57aSAndre Fischer+    public void openFile(URL scriptUrl, Scriptable scope, Runnable closeCallback) {
286*09c2d57aSAndre Fischer+        if (scope == null) {
287*09c2d57aSAndre Fischer+            MessageDialogWrapper.showMessageDialog(this,
288*09c2d57aSAndre Fischer+                "Can't compile scripts: no scope available",
289*09c2d57aSAndre Fischer+                "Open", JOptionPane.ERROR_MESSAGE);
290*09c2d57aSAndre Fischer+        } else {
291*09c2d57aSAndre Fischer+            if (scriptUrl != null) {
292*09c2d57aSAndre Fischer+                try
293*09c2d57aSAndre Fischer+                {
294*09c2d57aSAndre Fischer+                    InputStreamReader reader = new InputStreamReader(scriptUrl.openStream());
295*09c2d57aSAndre Fischer+                    String fileName = getFileName(scriptUrl);
296*09c2d57aSAndre Fischer+                    officeScripts.addScript( fileName, scriptUrl, scope, closeCallback  );
297*09c2d57aSAndre Fischer+                    RunProxy proxy = new RunProxy(this, RunProxy.OPEN_FILE);
298*09c2d57aSAndre Fischer+                    proxy.fileName = fileName;
299*09c2d57aSAndre Fischer+                    proxy.text = Kit.readReader(reader);
300*09c2d57aSAndre Fischer+                    new Thread(proxy).start();
301*09c2d57aSAndre Fischer+                }
302*09c2d57aSAndre Fischer+                catch ( IOException e )
303*09c2d57aSAndre Fischer+                {
304*09c2d57aSAndre Fischer+                    MessageDialogWrapper.showMessageDialog(this,
305*09c2d57aSAndre Fischer+                        "Can't open stream for script: " + e.toString(),
306*09c2d57aSAndre Fischer+                        "Open", JOptionPane.ERROR_MESSAGE);
307*09c2d57aSAndre Fischer+                }
308*09c2d57aSAndre Fischer+            }
309*09c2d57aSAndre Fischer+        }
310*09c2d57aSAndre Fischer+        split1.setDividerLocation(1.0);
311*09c2d57aSAndre Fischer+    }
312*09c2d57aSAndre Fischer+
313*09c2d57aSAndre Fischer+    // patched Office specific interface
314*09c2d57aSAndre Fischer+    OfficeScriptInfo officeScripts = new OfficeScriptInfo();
315*09c2d57aSAndre Fischer+
316*09c2d57aSAndre Fischer+    void removeScript(String url) {
317*09c2d57aSAndre Fischer+        officeScripts.deleteScript(url);
318*09c2d57aSAndre Fischer+    }
319*09c2d57aSAndre Fischer+
320*09c2d57aSAndre Fischer+    public void showScriptWindow(URL url) {
321*09c2d57aSAndre Fischer+        String key = getFileName(url);
322*09c2d57aSAndre Fischer+        FileWindow w = (FileWindow)getFileWindow(key);
323*09c2d57aSAndre Fischer+        if (w != null)
324*09c2d57aSAndre Fischer+        {
325*09c2d57aSAndre Fischer+            desk.getDesktopManager().deiconifyFrame(w);
326*09c2d57aSAndre Fischer+            desk.getDesktopManager().activateFrame(w);
327*09c2d57aSAndre Fischer+            w.show();
328*09c2d57aSAndre Fischer+            w.toFront();
329*09c2d57aSAndre Fischer+        }
330*09c2d57aSAndre Fischer+    }
331*09c2d57aSAndre Fischer+
332*09c2d57aSAndre Fischer+    public void highlighLineInScriptWindow(URL url, int lineNum) {
333*09c2d57aSAndre Fischer+        String key = getFileName(url);
334*09c2d57aSAndre Fischer+        FileWindow w = (FileWindow)getFileWindow(key);
335*09c2d57aSAndre Fischer+        if (w != null)
336*09c2d57aSAndre Fischer+        {
337*09c2d57aSAndre Fischer+            showFileWindow(key, lineNum);
338*09c2d57aSAndre Fischer+        }
339*09c2d57aSAndre Fischer+    }
340*09c2d57aSAndre Fischer+
341*09c2d57aSAndre Fischer+    public Object runScriptWindow(URL scriptUrl) throws Exception
342*09c2d57aSAndre Fischer+    {
343*09c2d57aSAndre Fischer+        String key = getFileName(scriptUrl);
344*09c2d57aSAndre Fischer+        FileWindow w = (FileWindow)getFileWindow(key);
345*09c2d57aSAndre Fischer+        Object result = null;
346*09c2d57aSAndre Fischer+        w.toFront();
347*09c2d57aSAndre Fischer+        if (w != null)
348*09c2d57aSAndre Fischer+        {
349*09c2d57aSAndre Fischer+            Scriptable scope = officeScripts.getScriptScope(key);
350*09c2d57aSAndre Fischer+            if (scope == null)
351*09c2d57aSAndre Fischer+            {
352*09c2d57aSAndre Fischer+                MessageDialogWrapper.showMessageDialog(this, "Can't load scripts: no scope available", "Run", JOptionPane.ERROR_MESSAGE);
353*09c2d57aSAndre Fischer+            }
354*09c2d57aSAndre Fischer+            else
355*09c2d57aSAndre Fischer+            {
356*09c2d57aSAndre Fischer+                String url = w.getUrl();
357*09c2d57aSAndre Fischer+                if (url != null)
358*09c2d57aSAndre Fischer+                {
359*09c2d57aSAndre Fischer+                    if (officeScripts.isScriptRunning(key))
360*09c2d57aSAndre Fischer+                    {
361*09c2d57aSAndre Fischer+                        return result;
362*09c2d57aSAndre Fischer+                    }
363*09c2d57aSAndre Fischer+                    officeScripts.setScriptRunning(key, true);
364*09c2d57aSAndre Fischer+                    try {
365*09c2d57aSAndre Fischer+                        result = dim.evalScriptWithReturn(url, w.textArea.getText(), scope);
366*09c2d57aSAndre Fischer+                    } catch (Exception exc) {
367*09c2d57aSAndre Fischer+                        exc.printStackTrace();
368*09c2d57aSAndre Fischer+                        throw exc;
369*09c2d57aSAndre Fischer+                    } finally {
370*09c2d57aSAndre Fischer+                        officeScripts.setScriptRunning(key, false);
371*09c2d57aSAndre Fischer+                    }
372*09c2d57aSAndre Fischer+                }
373*09c2d57aSAndre Fischer+            }
374*09c2d57aSAndre Fischer+        }
375*09c2d57aSAndre Fischer+        return result;
376*09c2d57aSAndre Fischer+    }
377*09c2d57aSAndre Fischer+
378*09c2d57aSAndre Fischer+    public boolean isModified(URL url)
379*09c2d57aSAndre Fischer+    {
380*09c2d57aSAndre Fischer+        String key = getFileName(url);
381*09c2d57aSAndre Fischer+        FileWindow w = (FileWindow)getFileWindow(key);
382*09c2d57aSAndre Fischer+        return w.isModified();
383*09c2d57aSAndre Fischer+    }
384*09c2d57aSAndre Fischer+
385*09c2d57aSAndre Fischer+    public String getText(URL url)
386*09c2d57aSAndre Fischer+    {
387*09c2d57aSAndre Fischer+        String key = getFileName(url);
388*09c2d57aSAndre Fischer+        FileWindow w = (FileWindow)getFileWindow(key);
389*09c2d57aSAndre Fischer+        return w.getText();
390*09c2d57aSAndre Fischer+    }
391*09c2d57aSAndre Fischer+
392*09c2d57aSAndre Fischer }
393*09c2d57aSAndre Fischer
394*09c2d57aSAndre Fischer /**
395*09c2d57aSAndre Fischer@@ -1590,7 +1733,9 @@
396*09c2d57aSAndre Fischer         case KeyEvent.VK_ENTER:
397*09c2d57aSAndre Fischer         case KeyEvent.VK_DELETE:
398*09c2d57aSAndre Fischer         case KeyEvent.VK_TAB:
399*09c2d57aSAndre Fischer-            e.consume();
400*09c2d57aSAndre Fischer+            if (! w.isEditable()) {
401*09c2d57aSAndre Fischer+                e.consume();
402*09c2d57aSAndre Fischer+            }
403*09c2d57aSAndre Fischer             break;
404*09c2d57aSAndre Fischer         }
405*09c2d57aSAndre Fischer     }
406*09c2d57aSAndre Fischer@@ -1599,14 +1744,18 @@
407*09c2d57aSAndre Fischer      * Called when a key is typed.
408*09c2d57aSAndre Fischer      */
409*09c2d57aSAndre Fischer     public void keyTyped(KeyEvent e) {
410*09c2d57aSAndre Fischer-        e.consume();
411*09c2d57aSAndre Fischer+        if (! w.isEditable()) {
412*09c2d57aSAndre Fischer+            e.consume();
413*09c2d57aSAndre Fischer+        }
414*09c2d57aSAndre Fischer     }
415*09c2d57aSAndre Fischer
416*09c2d57aSAndre Fischer     /**
417*09c2d57aSAndre Fischer      * Called when a key is released.
418*09c2d57aSAndre Fischer      */
419*09c2d57aSAndre Fischer     public void keyReleased(KeyEvent e) {
420*09c2d57aSAndre Fischer-        e.consume();
421*09c2d57aSAndre Fischer+        if (! w.isEditable()) {
422*09c2d57aSAndre Fischer+            e.consume();
423*09c2d57aSAndre Fischer+        }
424*09c2d57aSAndre Fischer     }
425*09c2d57aSAndre Fischer }
426*09c2d57aSAndre Fischer
427*09c2d57aSAndre Fischer@@ -2089,7 +2238,7 @@
428*09c2d57aSAndre Fischer /**
429*09c2d57aSAndre Fischer  * An internal frame for script files.
430*09c2d57aSAndre Fischer  */
431*09c2d57aSAndre Fischer-class FileWindow extends JInternalFrame implements ActionListener {
432*09c2d57aSAndre Fischer+class FileWindow extends JInternalFrame implements ActionListener, DocumentListener {
433*09c2d57aSAndre Fischer
434*09c2d57aSAndre Fischer     /**
435*09c2d57aSAndre Fischer      * Serializable magic number.
436*09c2d57aSAndre Fischer@@ -2126,6 +2275,7 @@
437*09c2d57aSAndre Fischer      */
438*09c2d57aSAndre Fischer     int currentPos;
439*09c2d57aSAndre Fischer
440*09c2d57aSAndre Fischer+    boolean isModified = false;
441*09c2d57aSAndre Fischer     /**
442*09c2d57aSAndre Fischer      * Loads the file.
443*09c2d57aSAndre Fischer      */
444*09c2d57aSAndre Fischer@@ -2134,11 +2284,62 @@
445*09c2d57aSAndre Fischer         if (url != null) {
446*09c2d57aSAndre Fischer             RunProxy proxy = new RunProxy(debugGui, RunProxy.LOAD_FILE);
447*09c2d57aSAndre Fischer             proxy.fileName = url;
448*09c2d57aSAndre Fischer-            proxy.text = sourceInfo.source();
449*09c2d57aSAndre Fischer+            proxy.text = textArea.getText();
450*09c2d57aSAndre Fischer+            proxy.scope = debugGui.officeScripts.getScriptScope(url);
451*09c2d57aSAndre Fischer             new Thread(proxy).start();
452*09c2d57aSAndre Fischer         }
453*09c2d57aSAndre Fischer     }
454*09c2d57aSAndre Fischer
455*09c2d57aSAndre Fischer+    void save() {
456*09c2d57aSAndre Fischer+        String url = getUrl();
457*09c2d57aSAndre Fischer+        if (url != null) {
458*09c2d57aSAndre Fischer+            OutputStream os = null;
459*09c2d57aSAndre Fischer+            try {
460*09c2d57aSAndre Fischer+                if (url.startsWith("vnd.sun.star"))
461*09c2d57aSAndre Fischer+                {
462*09c2d57aSAndre Fischer+                    URL scriptUrl = debugGui.officeScripts.getScriptUrl(url);
463*09c2d57aSAndre Fischer+                    if ( scriptUrl == null )
464*09c2d57aSAndre Fischer+                    {
465*09c2d57aSAndre Fischer+                        throw new IOException("Can't optain stream for " + url);
466*09c2d57aSAndre Fischer+                    }
467*09c2d57aSAndre Fischer+                    os = scriptUrl.openConnection().getOutputStream();
468*09c2d57aSAndre Fischer+                }
469*09c2d57aSAndre Fischer+                else
470*09c2d57aSAndre Fischer+                {
471*09c2d57aSAndre Fischer+                   os = new FileOutputStream(url);
472*09c2d57aSAndre Fischer+                }
473*09c2d57aSAndre Fischer+                String s = textArea.getText();
474*09c2d57aSAndre Fischer+                os.write(s.getBytes(), 0, s.length());
475*09c2d57aSAndre Fischer+
476*09c2d57aSAndre Fischer+                this.isModified = false;
477*09c2d57aSAndre Fischer+            } catch (IOException ioe) {
478*09c2d57aSAndre Fischer+                MessageDialogWrapper.showMessageDialog(this,
479*09c2d57aSAndre Fischer+                    "Error saving file: " + ioe.getMessage(),
480*09c2d57aSAndre Fischer+                    "Error", JOptionPane.ERROR_MESSAGE);
481*09c2d57aSAndre Fischer+            }
482*09c2d57aSAndre Fischer+            finally
483*09c2d57aSAndre Fischer+            {
484*09c2d57aSAndre Fischer+                if ( os != null )
485*09c2d57aSAndre Fischer+                {
486*09c2d57aSAndre Fischer+                    try
487*09c2d57aSAndre Fischer+                    {
488*09c2d57aSAndre Fischer+                        os.close();
489*09c2d57aSAndre Fischer+                        os = null;
490*09c2d57aSAndre Fischer+                    }
491*09c2d57aSAndre Fischer+                    catch( IOException ioe )
492*09c2d57aSAndre Fischer+                    {
493*09c2d57aSAndre Fischer+                        System.err.println("Error closing stream: " + ioe.getMessage() );
494*09c2d57aSAndre Fischer+                        ioe.printStackTrace();
495*09c2d57aSAndre Fischer+                    }
496*09c2d57aSAndre Fischer+                }
497*09c2d57aSAndre Fischer+            }
498*09c2d57aSAndre Fischer+        }
499*09c2d57aSAndre Fischer+    }
500*09c2d57aSAndre Fischer+
501*09c2d57aSAndre Fischer+    public boolean isEditable() {
502*09c2d57aSAndre Fischer+        return debugGui.isSourceEditingEnabled();
503*09c2d57aSAndre Fischer+    }
504*09c2d57aSAndre Fischer+
505*09c2d57aSAndre Fischer     /**
506*09c2d57aSAndre Fischer      * Returns the offset position for the given line.
507*09c2d57aSAndre Fischer      */
508*09c2d57aSAndre Fischer@@ -2214,7 +2415,16 @@
509*09c2d57aSAndre Fischer         pack();
510*09c2d57aSAndre Fischer         updateText(sourceInfo);
511*09c2d57aSAndre Fischer         textArea.select(0);
512*09c2d57aSAndre Fischer+        addInternalFrameListener( new InternalFrameAdapter() {
513*09c2d57aSAndre Fischer+            public void internalFrameClosed(InternalFrameEvent e) {
514*09c2d57aSAndre Fischer+                getDebugGui().removeScript( getUrl() );
515*09c2d57aSAndre Fischer+            }
516*09c2d57aSAndre Fischer+        } );
517*09c2d57aSAndre Fischer     }
518*09c2d57aSAndre Fischer+
519*09c2d57aSAndre Fischer+    public SwingGui getDebugGui() {
520*09c2d57aSAndre Fischer+        return debugGui;
521*09c2d57aSAndre Fischer+    }
522*09c2d57aSAndre Fischer
523*09c2d57aSAndre Fischer     /**
524*09c2d57aSAndre Fischer      * Updates the tool tip contents.
525*09c2d57aSAndre Fischer@@ -2249,7 +2459,10 @@
526*09c2d57aSAndre Fischer         this.sourceInfo = sourceInfo;
527*09c2d57aSAndre Fischer         String newText = sourceInfo.source();
528*09c2d57aSAndre Fischer         if (!textArea.getText().equals(newText)) {
529*09c2d57aSAndre Fischer+            textArea.getDocument().removeDocumentListener(this);
530*09c2d57aSAndre Fischer             textArea.setText(newText);
531*09c2d57aSAndre Fischer+            this.isModified = false;
532*09c2d57aSAndre Fischer+            textArea.getDocument().addDocumentListener(this);
533*09c2d57aSAndre Fischer             int pos = 0;
534*09c2d57aSAndre Fischer             if (currentPos != -1) {
535*09c2d57aSAndre Fischer                 pos = currentPos;
536*09c2d57aSAndre Fischer@@ -2260,6 +2473,31 @@
537*09c2d57aSAndre Fischer         fileHeader.repaint();
538*09c2d57aSAndre Fischer     }
539*09c2d57aSAndre Fischer
540*09c2d57aSAndre Fischer+    /* Implementation of DocumentListener interface */
541*09c2d57aSAndre Fischer+    public void insertUpdate(DocumentEvent e) {
542*09c2d57aSAndre Fischer+        doChanged(e);
543*09c2d57aSAndre Fischer+    }
544*09c2d57aSAndre Fischer+
545*09c2d57aSAndre Fischer+    public void removeUpdate(DocumentEvent e) {
546*09c2d57aSAndre Fischer+        doChanged(e);
547*09c2d57aSAndre Fischer+    }
548*09c2d57aSAndre Fischer+
549*09c2d57aSAndre Fischer+    public void changedUpdate(DocumentEvent e) {
550*09c2d57aSAndre Fischer+        doChanged(e);
551*09c2d57aSAndre Fischer+    }
552*09c2d57aSAndre Fischer+
553*09c2d57aSAndre Fischer+    public void doChanged(DocumentEvent e) {
554*09c2d57aSAndre Fischer+        this.isModified = true;
555*09c2d57aSAndre Fischer+    }
556*09c2d57aSAndre Fischer+
557*09c2d57aSAndre Fischer+    public boolean isModified() {
558*09c2d57aSAndre Fischer+        return this.isModified;
559*09c2d57aSAndre Fischer+    }
560*09c2d57aSAndre Fischer+
561*09c2d57aSAndre Fischer+    public String getText() {
562*09c2d57aSAndre Fischer+        return textArea.getText();
563*09c2d57aSAndre Fischer+    }
564*09c2d57aSAndre Fischer+
565*09c2d57aSAndre Fischer     /**
566*09c2d57aSAndre Fischer      * Sets the cursor position.
567*09c2d57aSAndre Fischer      */
568*09c2d57aSAndre Fischer@@ -2295,11 +2533,11 @@
569*09c2d57aSAndre Fischer     public void actionPerformed(ActionEvent e) {
570*09c2d57aSAndre Fischer         String cmd = e.getActionCommand();
571*09c2d57aSAndre Fischer         if (cmd.equals("Cut")) {
572*09c2d57aSAndre Fischer-            // textArea.cut();
573*09c2d57aSAndre Fischer+             textArea.cut();
574*09c2d57aSAndre Fischer         } else if (cmd.equals("Copy")) {
575*09c2d57aSAndre Fischer             textArea.copy();
576*09c2d57aSAndre Fischer         } else if (cmd.equals("Paste")) {
577*09c2d57aSAndre Fischer-            // textArea.paste();
578*09c2d57aSAndre Fischer+             textArea.paste();
579*09c2d57aSAndre Fischer         }
580*09c2d57aSAndre Fischer     }
581*09c2d57aSAndre Fischer }
582*09c2d57aSAndre Fischer@@ -2920,7 +3158,7 @@
583*09c2d57aSAndre Fischer      */
584*09c2d57aSAndre Fischer     public ContextWindow(final SwingGui debugGui) {
585*09c2d57aSAndre Fischer         this.debugGui = debugGui;
586*09c2d57aSAndre Fischer-        enabled = false;
587*09c2d57aSAndre Fischer+        enabled = true;
588*09c2d57aSAndre Fischer         JPanel left = new JPanel();
589*09c2d57aSAndre Fischer         JToolBar t1 = new JToolBar();
590*09c2d57aSAndre Fischer         t1.setName("Variables");
591*09c2d57aSAndre Fischer@@ -3161,6 +3399,10 @@
592*09c2d57aSAndre Fischer     public void enableUpdate() {
593*09c2d57aSAndre Fischer         enabled = true;
594*09c2d57aSAndre Fischer     }
595*09c2d57aSAndre Fischer+
596*09c2d57aSAndre Fischer+    public boolean isEnabled() {
597*09c2d57aSAndre Fischer+        return enabled;
598*09c2d57aSAndre Fischer+    }
599*09c2d57aSAndre Fischer
600*09c2d57aSAndre Fischer     // ActionListener
601*09c2d57aSAndre Fischer
602*09c2d57aSAndre Fischer@@ -3249,8 +3491,10 @@
603*09c2d57aSAndre Fischer     Menubar(SwingGui debugGui) {
604*09c2d57aSAndre Fischer         super();
605*09c2d57aSAndre Fischer         this.debugGui = debugGui;
606*09c2d57aSAndre Fischer-        String[] fileItems  = {"Open...", "Run...", "", "Exit"};
607*09c2d57aSAndre Fischer-        String[] fileCmds  = {"Open", "Load", "", "Exit"};
608*09c2d57aSAndre Fischer+        // String[] fileItems  = {"Open...", "Run...", "", "Exit"};
609*09c2d57aSAndre Fischer+        // String[] fileCmds  = {"Open", "Load", "", "Exit"};
610*09c2d57aSAndre Fischer+        String[] fileItems  = {"Run", "Save", "", "Exit"};
611*09c2d57aSAndre Fischer+        String[] fileCmds  = {"Run", "Save", "", "Exit"};
612*09c2d57aSAndre Fischer         char[] fileShortCuts = {'0', 'N', 0, 'X'};
613*09c2d57aSAndre Fischer         int[] fileAccelerators = {KeyEvent.VK_O,
614*09c2d57aSAndre Fischer                                   KeyEvent.VK_N,
615*09c2d57aSAndre Fischer@@ -3299,6 +3543,8 @@
616*09c2d57aSAndre Fischer                                            editShortCuts[i]);
617*09c2d57aSAndre Fischer             item.addActionListener(this);
618*09c2d57aSAndre Fischer             editMenu.add(item);
619*09c2d57aSAndre Fischer+            if (i < 3)
620*09c2d57aSAndre Fischer+                runOnlyItems.add(item);
621*09c2d57aSAndre Fischer         }
622*09c2d57aSAndre Fischer         for (int i = 0; i < plafItems.length; ++i) {
623*09c2d57aSAndre Fischer             JMenuItem item = new JMenuItem(plafItems[i],
624*09c2d57aSAndre Fischer@@ -3348,9 +3594,9 @@
625*09c2d57aSAndre Fischer         item.addActionListener(this);
626*09c2d57aSAndre Fischer         windowMenu.add(item = new JMenuItem("Tile", 'T'));
627*09c2d57aSAndre Fischer         item.addActionListener(this);
628*09c2d57aSAndre Fischer-        windowMenu.addSeparator();
629*09c2d57aSAndre Fischer-        windowMenu.add(item = new JMenuItem("Console", 'C'));
630*09c2d57aSAndre Fischer-        item.addActionListener(this);
631*09c2d57aSAndre Fischer+        // windowMenu.addSeparator();
632*09c2d57aSAndre Fischer+        // windowMenu.add(item = new JMenuItem("Console", 'C'));
633*09c2d57aSAndre Fischer+        // item.addActionListener(this);
634*09c2d57aSAndre Fischer         add(windowMenu);
635*09c2d57aSAndre Fischer
636*09c2d57aSAndre Fischer         updateEnabled(false);
637*09c2d57aSAndre Fischer@@ -3530,6 +3776,11 @@
638*09c2d57aSAndre Fischer      * interruption, if any.
639*09c2d57aSAndre Fischer      */
640*09c2d57aSAndre Fischer     String alertMessage;
641*09c2d57aSAndre Fischer+
642*09c2d57aSAndre Fischer+    /**
643*09c2d57aSAndre Fischer+     * The arguments for evaluation.
644*09c2d57aSAndre Fischer+     */
645*09c2d57aSAndre Fischer+    Scriptable scope;
646*09c2d57aSAndre Fischer
647*09c2d57aSAndre Fischer     /**
648*09c2d57aSAndre Fischer      * Creates a new RunProxy.
649*09c2d57aSAndre Fischer@@ -3556,7 +3807,10 @@
650*09c2d57aSAndre Fischer
651*09c2d57aSAndre Fischer           case LOAD_FILE:
652*09c2d57aSAndre Fischer             try {
653*09c2d57aSAndre Fischer-                debugGui.dim.evalScript(fileName, text);
654*09c2d57aSAndre Fischer+                if (scope != null)
655*09c2d57aSAndre Fischer+                    debugGui.dim.evalScriptWithReturn(fileName, text, scope);
656*09c2d57aSAndre Fischer+                else
657*09c2d57aSAndre Fischer+                    debugGui.dim.evalScript(fileName, text);
658*09c2d57aSAndre Fischer             } catch (RuntimeException ex) {
659*09c2d57aSAndre Fischer                 MessageDialogWrapper.showMessageDialog(
660*09c2d57aSAndre Fischer                     debugGui, ex.getMessage(), "Run error for "+fileName,
661*09c2d57aSAndre FischerIndex: toolsrc/org/mozilla/javascript/tools/debugger/OfficeScriptInfo.java
662*09c2d57aSAndre Fischer===================================================================
663*09c2d57aSAndre Fischer--- toolsrc/org/mozilla/javascript/tools/debugger/OfficeScriptInfo.java	(revision 2)
664*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/toolsrc/org/mozilla/javascript/tools/debugger/OfficeScriptInfo.java	(working copy)
665*09c2d57aSAndre Fischer@@ -1 +1,124 @@
666*09c2d57aSAndre Fischer-dummy
667*09c2d57aSAndre Fischer+/**************************************************************
668*09c2d57aSAndre Fischer+ *
669*09c2d57aSAndre Fischer+ * Licensed to the Apache Software Foundation (ASF) under one
670*09c2d57aSAndre Fischer+ * or more contributor license agreements.  See the NOTICE file
671*09c2d57aSAndre Fischer+ * distributed with this work for additional information
672*09c2d57aSAndre Fischer+ * regarding copyright ownership.  The ASF licenses this file
673*09c2d57aSAndre Fischer+ * to you under the Apache License, Version 2.0 (the
674*09c2d57aSAndre Fischer+ * "License"); you may not use this file except in compliance
675*09c2d57aSAndre Fischer+ * with the License.  You may obtain a copy of the License at
676*09c2d57aSAndre Fischer+ *
677*09c2d57aSAndre Fischer+ *   http://www.apache.org/licenses/LICENSE-2.0
678*09c2d57aSAndre Fischer+ *
679*09c2d57aSAndre Fischer+ * Unless required by applicable law or agreed to in writing,
680*09c2d57aSAndre Fischer+ * software distributed under the License is distributed on an
681*09c2d57aSAndre Fischer+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
682*09c2d57aSAndre Fischer+ * KIND, either express or implied.  See the License for the
683*09c2d57aSAndre Fischer+ * specific language governing permissions and limitations
684*09c2d57aSAndre Fischer+ * under the License.
685*09c2d57aSAndre Fischer+ *
686*09c2d57aSAndre Fischer+ *************************************************************/
687*09c2d57aSAndre Fischer+
688*09c2d57aSAndre Fischer+
689*09c2d57aSAndre Fischer+package org.mozilla.javascript.tools.debugger;
690*09c2d57aSAndre Fischer+import java.net.URL;
691*09c2d57aSAndre Fischer+import java.util.Hashtable;
692*09c2d57aSAndre Fischer+import org.mozilla.javascript.Scriptable;
693*09c2d57aSAndre Fischer+
694*09c2d57aSAndre Fischer+public class OfficeScriptInfo
695*09c2d57aSAndre Fischer+{
696*09c2d57aSAndre Fischer+    private Hashtable<String, SFScriptInfo> loadedSFScripts = new Hashtable<String, SFScriptInfo>();
697*09c2d57aSAndre Fischer+
698*09c2d57aSAndre Fischer+    public void addScript( URL url, Scriptable scope, Runnable closeCallback )
699*09c2d57aSAndre Fischer+    {
700*09c2d57aSAndre Fischer+        addScript( url.toString(), url, scope, closeCallback );
701*09c2d57aSAndre Fischer+    }
702*09c2d57aSAndre Fischer+
703*09c2d57aSAndre Fischer+    public void addScript( String key, URL url, Scriptable scope, Runnable closeCallback )
704*09c2d57aSAndre Fischer+    {
705*09c2d57aSAndre Fischer+        SFScriptInfo si = (SFScriptInfo)loadedSFScripts.get( key );
706*09c2d57aSAndre Fischer+        if ( si == null )
707*09c2d57aSAndre Fischer+        {
708*09c2d57aSAndre Fischer+            si = new SFScriptInfo();
709*09c2d57aSAndre Fischer+            si.url = url;
710*09c2d57aSAndre Fischer+            si.scope = scope;
711*09c2d57aSAndre Fischer+            si.closeCallback = closeCallback;
712*09c2d57aSAndre Fischer+            loadedSFScripts.put( key, si );
713*09c2d57aSAndre Fischer+        }
714*09c2d57aSAndre Fischer+    }
715*09c2d57aSAndre Fischer+
716*09c2d57aSAndre Fischer+    public void deleteScript( String key )
717*09c2d57aSAndre Fischer+    {
718*09c2d57aSAndre Fischer+        SFScriptInfo info = (SFScriptInfo)loadedSFScripts.remove( key );
719*09c2d57aSAndre Fischer+        if ( info != null )
720*09c2d57aSAndre Fischer+        {
721*09c2d57aSAndre Fischer+            if ( info.closeCallback != null )
722*09c2d57aSAndre Fischer+            {
723*09c2d57aSAndre Fischer+                System.out.println("** In removeSFScriptInfo  have callback for " + key );
724*09c2d57aSAndre Fischer+                info.closeCallback.run(); // really need to do this in seperate thread????
725*09c2d57aSAndre Fischer+            }
726*09c2d57aSAndre Fischer+        }
727*09c2d57aSAndre Fischer+    }
728*09c2d57aSAndre Fischer+
729*09c2d57aSAndre Fischer+    public Scriptable getScriptScope( String key )
730*09c2d57aSAndre Fischer+    {
731*09c2d57aSAndre Fischer+        Scriptable result = null;
732*09c2d57aSAndre Fischer+        SFScriptInfo info = (SFScriptInfo)loadedSFScripts.get( key );
733*09c2d57aSAndre Fischer+        if ( info != null )
734*09c2d57aSAndre Fischer+        {
735*09c2d57aSAndre Fischer+            result = info.scope;
736*09c2d57aSAndre Fischer+        }
737*09c2d57aSAndre Fischer+        return result;
738*09c2d57aSAndre Fischer+    }
739*09c2d57aSAndre Fischer+
740*09c2d57aSAndre Fischer+    public URL getScriptUrl( String key )
741*09c2d57aSAndre Fischer+    {
742*09c2d57aSAndre Fischer+        URL result = null;
743*09c2d57aSAndre Fischer+        SFScriptInfo info = (SFScriptInfo)loadedSFScripts.get( key );
744*09c2d57aSAndre Fischer+        if ( info != null )
745*09c2d57aSAndre Fischer+        {
746*09c2d57aSAndre Fischer+            result = info.url;
747*09c2d57aSAndre Fischer+        }
748*09c2d57aSAndre Fischer+        return result;
749*09c2d57aSAndre Fischer+    }
750*09c2d57aSAndre Fischer+    public boolean hasScript( String key )
751*09c2d57aSAndre Fischer+    {
752*09c2d57aSAndre Fischer+        boolean result = true;
753*09c2d57aSAndre Fischer+        SFScriptInfo info = (SFScriptInfo)loadedSFScripts.get( key );
754*09c2d57aSAndre Fischer+        if ( info == null )
755*09c2d57aSAndre Fischer+        {
756*09c2d57aSAndre Fischer+            result = false;
757*09c2d57aSAndre Fischer+        }
758*09c2d57aSAndre Fischer+        return result;
759*09c2d57aSAndre Fischer+    }
760*09c2d57aSAndre Fischer+
761*09c2d57aSAndre Fischer+    public void setScriptRunning( String key, boolean running )
762*09c2d57aSAndre Fischer+    {
763*09c2d57aSAndre Fischer+        SFScriptInfo info = (SFScriptInfo)loadedSFScripts.get( key );
764*09c2d57aSAndre Fischer+        if ( info != null )
765*09c2d57aSAndre Fischer+        {
766*09c2d57aSAndre Fischer+            info.isExecuting = running;
767*09c2d57aSAndre Fischer+        }
768*09c2d57aSAndre Fischer+    }
769*09c2d57aSAndre Fischer+
770*09c2d57aSAndre Fischer+    public boolean isScriptRunning( String key )
771*09c2d57aSAndre Fischer+    {
772*09c2d57aSAndre Fischer+        boolean result = false;
773*09c2d57aSAndre Fischer+        SFScriptInfo info = (SFScriptInfo)loadedSFScripts.get( key );
774*09c2d57aSAndre Fischer+        if ( info != null )
775*09c2d57aSAndre Fischer+        {
776*09c2d57aSAndre Fischer+            result = info.isExecuting;
777*09c2d57aSAndre Fischer+        }
778*09c2d57aSAndre Fischer+        return result;
779*09c2d57aSAndre Fischer+    }
780*09c2d57aSAndre Fischer+
781*09c2d57aSAndre Fischer+
782*09c2d57aSAndre Fischer+
783*09c2d57aSAndre Fischer+    class SFScriptInfo
784*09c2d57aSAndre Fischer+    {
785*09c2d57aSAndre Fischer+        Scriptable scope;
786*09c2d57aSAndre Fischer+        boolean isExecuting;
787*09c2d57aSAndre Fischer+        URL url;
788*09c2d57aSAndre Fischer+        Runnable closeCallback;
789*09c2d57aSAndre Fischer+    }
790*09c2d57aSAndre Fischer+}
791*09c2d57aSAndre FischerIndex: toolsrc/build.xml
792*09c2d57aSAndre Fischer===================================================================
793*09c2d57aSAndre Fischer--- toolsrc/build.xml	(revision 1)
794*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/toolsrc/build.xml	(working copy)
795*09c2d57aSAndre Fischer@@ -40,6 +40,24 @@
796*09c2d57aSAndre Fischer -->
797*09c2d57aSAndre Fischer <project name="toolsrc" default="compile" basedir="..">
798*09c2d57aSAndre Fischer
799*09c2d57aSAndre Fischer+  <condition property="boot_refID" value="macPath" else="nonMacPath">
800*09c2d57aSAndre Fischer+    <and>
801*09c2d57aSAndre Fischer+      <os family="mac"/>
802*09c2d57aSAndre Fischer+      <os family="unix"/>
803*09c2d57aSAndre Fischer+    </and>
804*09c2d57aSAndre Fischer+  </condition>
805*09c2d57aSAndre Fischer+  <path id="macPath" location="${java.home}/../Classes/classes.jar"/>
806*09c2d57aSAndre Fischer+  <!-- rhino.jar from OpenJDK breaks build -->
807*09c2d57aSAndre Fischer+  <path id="nonMacPath">
808*09c2d57aSAndre Fischer+    <fileset dir="${java.home}/">
809*09c2d57aSAndre Fischer+       <include name="jre/lib/*.jar"/>
810*09c2d57aSAndre Fischer+       <include name="lib/*.jar"/>
811*09c2d57aSAndre Fischer+       <exclude name="jre/lib/rhino.jar"/>
812*09c2d57aSAndre Fischer+       <exclude name="lib/rhino.jar"/>
813*09c2d57aSAndre Fischer+     </fileset>
814*09c2d57aSAndre Fischer+  </path>
815*09c2d57aSAndre Fischer+  <path id="my.bootstrap.classpath" refID="${boot_refID}"/>
816*09c2d57aSAndre Fischer+
817*09c2d57aSAndre Fischer   <target name="properties">
818*09c2d57aSAndre Fischer     <property file="build.properties"/>
819*09c2d57aSAndre Fischer   </target>
820*09c2d57aSAndre FischerIndex: src/org/mozilla/javascript/DefiningClassLoader.java
821*09c2d57aSAndre Fischer===================================================================
822*09c2d57aSAndre Fischer--- src/org/mozilla/javascript/DefiningClassLoader.java	(revision 1)
823*09c2d57aSAndre Fischer+++ misc/build/rhino1_7R3/src/org/mozilla/javascript/DefiningClassLoader.java	(working copy)
824*09c2d57aSAndre Fischer@@ -39,6 +39,8 @@
825*09c2d57aSAndre Fischer
826*09c2d57aSAndre Fischer package org.mozilla.javascript;
827*09c2d57aSAndre Fischer
828*09c2d57aSAndre Fischer+import java.lang.reflect.Method;
829*09c2d57aSAndre Fischer+import java.lang.reflect.InvocationTargetException;
830*09c2d57aSAndre Fischer /**
831*09c2d57aSAndre Fischer  * Load generated classes.
832*09c2d57aSAndre Fischer  *
833*09c2d57aSAndre Fischer@@ -48,13 +50,33 @@
834*09c2d57aSAndre Fischer     implements GeneratedClassLoader
835*09c2d57aSAndre Fischer {
836*09c2d57aSAndre Fischer     public DefiningClassLoader() {
837*09c2d57aSAndre Fischer-        this.parentLoader = getClass().getClassLoader();
838*09c2d57aSAndre Fischer+		this.parentLoader = getClass().getClassLoader();
839*09c2d57aSAndre Fischer+        init();
840*09c2d57aSAndre Fischer     }
841*09c2d57aSAndre Fischer
842*09c2d57aSAndre Fischer     public DefiningClassLoader(ClassLoader parentLoader) {
843*09c2d57aSAndre Fischer-        this.parentLoader = parentLoader;
844*09c2d57aSAndre Fischer+		this.parentLoader = parentLoader;
845*09c2d57aSAndre Fischer+        init();
846*09c2d57aSAndre Fischer     }
847*09c2d57aSAndre Fischer
848*09c2d57aSAndre Fischer+    private void init() {
849*09c2d57aSAndre Fischer+        this.contextLoader = null;
850*09c2d57aSAndre Fischer+        if (method_getContextClassLoader != null) {
851*09c2d57aSAndre Fischer+            try {
852*09c2d57aSAndre Fischer+                this.contextLoader = (ClassLoader)
853*09c2d57aSAndre Fischer+                    method_getContextClassLoader.invoke(
854*09c2d57aSAndre Fischer+                        Thread.currentThread(),
855*09c2d57aSAndre Fischer+                        ScriptRuntime.emptyArgs);
856*09c2d57aSAndre Fischer+            } catch (IllegalAccessException ex) {
857*09c2d57aSAndre Fischer+            } catch (InvocationTargetException ex) {
858*09c2d57aSAndre Fischer+            } catch (SecurityException ex) {
859*09c2d57aSAndre Fischer+            }
860*09c2d57aSAndre Fischer+            if (this.contextLoader == this.parentLoader) {
861*09c2d57aSAndre Fischer+                this.contextLoader = null;
862*09c2d57aSAndre Fischer+            }
863*09c2d57aSAndre Fischer+        }
864*09c2d57aSAndre Fischer+    }
865*09c2d57aSAndre Fischer+
866*09c2d57aSAndre Fischer     public Class<?> defineClass(String name, byte[] data) {
867*09c2d57aSAndre Fischer         // Use our own protection domain for the generated classes.
868*09c2d57aSAndre Fischer         // TODO: we might want to use a separate protection domain for classes
869*09c2d57aSAndre Fischer@@ -73,10 +95,14 @@
870*09c2d57aSAndre Fischer     {
871*09c2d57aSAndre Fischer         Class<?> cl = findLoadedClass(name);
872*09c2d57aSAndre Fischer         if (cl == null) {
873*09c2d57aSAndre Fischer-            if (parentLoader != null) {
874*09c2d57aSAndre Fischer-                cl = parentLoader.loadClass(name);
875*09c2d57aSAndre Fischer+            if (contextLoader == null) {
876*09c2d57aSAndre Fischer+                cl = loadFromParent(name);
877*09c2d57aSAndre Fischer             } else {
878*09c2d57aSAndre Fischer-                cl = findSystemClass(name);
879*09c2d57aSAndre Fischer+                try {
880*09c2d57aSAndre Fischer+                    cl = loadFromParent(name);
881*09c2d57aSAndre Fischer+                } catch (ClassNotFoundException ex) {
882*09c2d57aSAndre Fischer+                    cl = contextLoader.loadClass(name);
883*09c2d57aSAndre Fischer+                }
884*09c2d57aSAndre Fischer             }
885*09c2d57aSAndre Fischer         }
886*09c2d57aSAndre Fischer         if (resolve) {
887*09c2d57aSAndre Fischer@@ -85,5 +111,36 @@
888*09c2d57aSAndre Fischer         return cl;
889*09c2d57aSAndre Fischer     }
890*09c2d57aSAndre Fischer
891*09c2d57aSAndre Fischer+    private Class loadFromParent(String name)
892*09c2d57aSAndre Fischer+        throws ClassNotFoundException
893*09c2d57aSAndre Fischer+    {
894*09c2d57aSAndre Fischer+        if (parentLoader != null) {
895*09c2d57aSAndre Fischer+            return parentLoader.loadClass(name);
896*09c2d57aSAndre Fischer+        } else {
897*09c2d57aSAndre Fischer+            return findSystemClass(name);
898*09c2d57aSAndre Fischer+        }
899*09c2d57aSAndre Fischer+    }
900*09c2d57aSAndre Fischer+
901*09c2d57aSAndre Fischer     private final ClassLoader parentLoader;
902*09c2d57aSAndre Fischer+
903*09c2d57aSAndre Fischer+    private ClassLoader contextLoader;
904*09c2d57aSAndre Fischer+
905*09c2d57aSAndre Fischer+    // We'd like to use "Thread.getContextClassLoader", but
906*09c2d57aSAndre Fischer+    // that's only available on Java2.
907*09c2d57aSAndre Fischer+    private static Method method_getContextClassLoader;
908*09c2d57aSAndre Fischer+
909*09c2d57aSAndre Fischer+    static {
910*09c2d57aSAndre Fischer+        try {
911*09c2d57aSAndre Fischer+            // Don't use "Thread.class": that performs the lookup
912*09c2d57aSAndre Fischer+            // in the class initializer, which doesn't allow us to
913*09c2d57aSAndre Fischer+            // catch possible security exceptions.
914*09c2d57aSAndre Fischer+            Class threadClass = Class.forName("java.lang.Thread");
915*09c2d57aSAndre Fischer+            method_getContextClassLoader =
916*09c2d57aSAndre Fischer+                threadClass.getDeclaredMethod("getContextClassLoader",
917*09c2d57aSAndre Fischer+                                               new Class[0]);
918*09c2d57aSAndre Fischer+        } catch (ClassNotFoundException e) {
919*09c2d57aSAndre Fischer+        } catch (NoSuchMethodException e) {
920*09c2d57aSAndre Fischer+        } catch (SecurityException e) {
921*09c2d57aSAndre Fischer+        }
922*09c2d57aSAndre Fischer+    }
923*09c2d57aSAndre Fischer }
924