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

221 by mattgiuca
editor: Made saving work.
1
saved_status = null;
2
3
function save_file()
4
{
5
    filename = document.getElementById("save_filename").value;
233 by mattgiuca
Added a shaky implementation of EditArea as the text editor.
6
    data = editAreaLoader.getValue("editbox");
221 by mattgiuca
editor: Made saving work.
7
    do_action("putfile", filename, {"path":".", "data":data});
8
    saved_status.data = "Saved.";
9
}
10
11
function edit_text()
12
{
13
    saved_status.data = "Not saved.";
14
}
220 by mattgiuca
browser: Removed 3 buttons which didn't do anything.
15
16
/** Presents the text editor.
17
 */
18
function handle_text(path, text, handler_type)
19
{
20
    /* Create a textarea with the text in it
21
     * (The makings of a primitive editor).
22
     */
23
24
    setmode(true);
25
    var files = document.getElementById("filesbody");
26
    var div = document.createElement("div");
27
    files.appendChild(div);
28
    div.setAttribute("class", "padding");
221 by mattgiuca
editor: Made saving work.
29
30
    /* Set up minimal interface */
31
    var p = dom_make_text_elem("p", "Path: ");
32
    var pathname = document.createElement("input");
33
    pathname.setAttribute("type", "text");
34
    pathname.setAttribute("size", "30");
35
    pathname.setAttribute("id", "save_filename");
36
    pathname.setAttribute("value", path);
37
    p.appendChild(pathname);
38
    var savebutton = document.createElement("input");
39
    savebutton.setAttribute("type", "button");
40
    savebutton.setAttribute("value", "Save");
41
    savebutton.setAttribute("onclick", "save_file()");
42
    p.appendChild(savebutton);
43
    var t = document.createTextNode(" ");
44
    p.appendChild(t);
45
    saved_status = document.createTextNode("Saved.");
46
    //p.appendChild(saved_status);
47
    div.appendChild(p);
48
49
    /* Print a warning message if this is not actually a text file.
220 by mattgiuca
browser: Removed 3 buttons which didn't do anything.
50
     */
51
    if (handler_type != "text")
52
    {
53
        var warn = dom_make_text_elem("p",
54
            "Warning: You are editing a binary " +
55
            "file, which explains any strange characters you may see. If " +
56
            "you save this file, you could corrupt it.");
57
        div.appendChild(warn);
58
    }
59
    var txt_elem = dom_make_text_elem("textarea",
60
        text.toString())
61
    div.appendChild(txt_elem);
62
    txt_elem.setAttribute("id", "editbox");
221 by mattgiuca
editor: Made saving work.
63
    txt_elem.setAttribute("onchange", "edit_text()");
220 by mattgiuca
browser: Removed 3 buttons which didn't do anything.
64
    /* TODO: Make CSS height: 100% work */
254 by mattgiuca
editor.js: Extended edit box to 35 lines (was too small).
65
    txt_elem.setAttribute("rows", "35");
233 by mattgiuca
Added a shaky implementation of EditArea as the text editor.
66
67
    /* Load EditArea into the editbox */
68
    editAreaLoader.init({
69
        id : "editbox",
70
        syntax: "python",
71
        start_highlight: true
72
    });
220 by mattgiuca
browser: Removed 3 buttons which didn't do anything.
73
}
74