~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to www/media/console/console.js

  • Committer: mattgiuca
  • Date: 2008-02-29 01:18:22 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:621
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic
    skeleton.
    "home" is the new default app, replacing "files".
    (It has a link to files).

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
windowpane_mode = false;
35
35
server_started = false;
36
36
 
37
 
interrupted = false;
38
 
 
39
37
/* Starts the console server, if it isn't already.
40
38
 * This can be called any number of times - it only starts the one server.
41
39
 * Note that this is asynchronous. It will return after signalling to start
63
61
            if (callback != null)
64
62
                callback();
65
63
        }
66
 
 
67
 
    //var current_path;
68
 
    if(typeof(current_path) != 'undefined')
69
 
    {
70
 
        // We have a current_path - give a suggestion to the server
71
 
        var path;
72
 
        if (current_file.isdir)
73
 
        {
74
 
            // Browser
75
 
            path = path_join("/home", current_path);
76
 
        }
77
 
        else
78
 
        {
79
 
            // Editor - need to chop off filename
80
 
            var tmp_path = current_path.split('/');
81
 
            tmp_path.pop();
82
 
            path = path_join("/home", tmp_path.join('/'));
83
 
        }
84
 
        ajax_call(callback1, "consoleservice", "start", {"startdir": path}, "POST");
85
 
    }
86
 
    else
87
 
    {
88
 
        // No current_path - let the server decide
89
 
        ajax_call(callback1, "consoleservice", "start", {}, "POST");
90
 
    }
 
64
    ajax_call(callback1, "consoleservice", "start", {}, "POST");
91
65
}
92
66
 
93
67
/** Initialises the console. All apps which import console are required to
110
84
        windowpane_mode = true;
111
85
        console_minimize();
112
86
    }
 
87
    /* TEMP: Start the server now.
 
88
     * Ultimately we want the server to start only when a line is typed, but
 
89
     * it currently does it asynchronously and doesn't start in time for the
 
90
     * first line. */
 
91
    start_server();
113
92
}
114
93
 
115
94
/** Hide the main console panel, so the console minimizes to just an input box
128
107
    if (!windowpane_mode) return;
129
108
    console_body.setAttribute("class", "windowpane maximal");
130
109
    console_filler.setAttribute("class", "windowpane maximal");
 
110
    /* Focus the input box by default */
 
111
    document.getElementById("console_inputText").focus()
131
112
}
132
113
 
133
114
/* current_text is the string currently on the command line.
230
211
 
231
212
var hist = new History();
232
213
 
233
 
function set_interrupt()
234
 
{
235
 
    interrupted = true;
236
 
}
237
 
 
238
 
function clear_output()
239
 
{
240
 
    var output = document.getElementById("console_output");
241
 
    while (output.firstChild)
242
 
    {
243
 
        output.removeChild(output.firstChild);
244
 
    }
245
 
}
246
 
 
247
214
/** Send a line of text to the Python server, wait for its return, and react
248
215
 * to its response by writing to the output box.
249
216
 * Also maximize the console window if not already.
250
217
 */
251
218
function console_enter_line(inputbox, which)
252
219
{
253
 
    interrupted = false;
254
 
 
255
220
    if (typeof(inputbox) == "string")
256
221
    {
257
222
        var inputline = inputbox;
267
232
    }
268
233
    var output = document.getElementById("console_output");
269
234
    {
270
 
        // Print ">>>" span
271
 
        var span = document.createElement("span");
272
 
        span.setAttribute("class", "inputPrompt");
273
 
        span.appendChild(document.createTextNode(">>> "));
274
 
        output.appendChild(span);
275
 
        // Print input line itself in a span
276
235
        var span = document.createElement("span");
277
236
        span.setAttribute("class", "inputMsg");
278
237
        span.appendChild(document.createTextNode(inputline + "\n"));
291
250
 
292
251
function console_response(inputbox, graytimer, inputline, responseText)
293
252
{
294
 
    try
295
 
    {
296
 
        var res = JSON.parse(responseText);
297
 
    }
298
 
    catch (e)
299
 
    {
300
 
        alert("An internal error occurred in the python console.");
301
 
        return;
302
 
    }
 
253
    var res = JSON.parse(responseText);
303
254
    var output = document.getElementById("console_output");
304
255
    if (res.hasOwnProperty('okay'))
305
256
    {
 
257
        // Success!
 
258
        if (res.okay)
 
259
        {
 
260
            output.appendChild(document.createTextNode(res.okay + "\n"));
 
261
            output.appendChild(span);
 
262
        }
306
263
        // set the prompt to >>>
307
264
        var prompt = document.getElementById("console_prompt");
308
265
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
315
272
        span.setAttribute("class", "errorMsg");
316
273
        span.appendChild(document.createTextNode(res.exc + "\n"));
317
274
        output.appendChild(span);
318
 
        // set the prompt to >>>
319
 
        var prompt = document.getElementById("console_prompt");
320
 
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
321
 
    }
322
 
    else if (res.hasOwnProperty('restart') && res.hasOwnProperty('key'))
323
 
    {
324
 
        // Server has indicated that the console should be restarted
325
 
        
326
 
        // Get the new key (host, port, magic)
327
 
        server_key = res.key;
328
 
 
329
 
        // Print a reason to explain why we'd do such a horrible thing
330
 
        // (console timeout, server error etc.)
331
 
        var span = document.createElement("span");
332
 
        span.setAttribute("class", "errorMsg");
333
 
        span.appendChild(document.createTextNode("Console Restart: " + res.restart + "\n"));
334
 
        output.appendChild(span);
335
 
        // set the prompt to >>>
336
 
        var prompt = document.getElementById("console_prompt");
337
 
        prompt.replaceChild(document.createTextNode(">>> "), prompt.firstChild);
338
 
 
339
275
    }
340
276
    else if (res.hasOwnProperty('more'))
341
277
    {
354
290
                console_response(inputbox, graytimer,
355
291
                                 null, xhr.responseText);
356
292
            }
357
 
        if (interrupted)
358
 
        {
359
 
            var kind = "interrupt";
360
 
        }
361
 
        else
362
 
        {
363
 
            var kind = "chat";
364
 
        }
365
293
        var args = {"key": server_key, "text":''};
366
 
        ajax_call(callback, "consoleservice", kind, args, "POST");
367
 
 
368
 
        // Open up the console so we can see the output
369
 
        // FIXME: do we need to maximize here?
370
 
        console_maximize();
371
 
 
372
 
        /* Auto-scrolling */
373
 
        divScroll.activeScroll();
374
 
 
 
294
        ajax_call(callback, "consoleservice", "chat", args, "POST");
375
295
        // Return early, so we don't re-enable the input box.
376
296
        return;
377
297
    }
387
307
        clearTimeout(graytimer);
388
308
        inputbox.removeAttribute("disabled");
389
309
        inputbox.removeAttribute("class");
390
 
        interrupted = false;
391
310
    }
392
311
 
393
312
    /* Open up the console so we can see the output */
394
313
    console_maximize();
395
314
    /* Auto-scrolling */
396
315
    divScroll.activeScroll();
397
 
 
398
 
    // Focus the input box by default
399
 
    document.getElementById("console_output").focus()
400
 
    document.getElementById("console_inputText").focus()
401
316
}
402
317
 
403
318
function catch_input(key)