809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
1 |
function disable_save_if_safe() |
2 |
{
|
|
3 |
/* If this is defined, this engine supports change notification, so is able
|
|
4 |
* to enable the button again. Disable it for them. */
|
|
5 |
if(editbox.editor.addChangeHandler) |
|
6 |
{
|
|
7 |
var savebutton = document.getElementById("save_button"); |
|
8 |
savebutton.disabled = true; |
|
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
9 |
window.onbeforeunload = null; |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
10 |
}
|
11 |
}
|
|
12 |
||
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
13 |
function save_file(filename) |
221
by mattgiuca
editor: Made saving work. |
14 |
{
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
15 |
data = editbox.getCode(); |
385
by mattgiuca
browser/editor: Clicking "Save" in the editor does not cause a page refresh |
16 |
/* Do NOT refresh the page contents (causes problems for editarea and is
|
17 |
* unnecessary). */
|
|
906
by wagrant
editor.js: Warn before saving if the open file is an old revision. |
18 |
if (current_file.svnstatus != "revision" || |
19 |
confirm("You are currently viewing an older version of this file. " + |
|
20 |
"Saving will overwrite the current version. " + |
|
21 |
"Are you sure you want to continue?")) |
|
22 |
{
|
|
23 |
do_action("putfile", filename, |
|
24 |
{"path":".", "data":data, "overwrite":"true"}, |
|
25 |
"multipart/form-data", true); |
|
26 |
disable_save_if_safe(); |
|
27 |
}
|
|
221
by mattgiuca
editor: Made saving work. |
28 |
}
|
29 |
||
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
30 |
function save_file_as(default_filename) |
31 |
{
|
|
839
by wagrant
Prompt on Save As if it would overwrite. |
32 |
filename = prompt("Path to save to:", default_filename); |
33 |
if (!filename) return; |
|
34 |
||
35 |
/* The filename will be path_joined with the app name, so needs to not
|
|
36 |
* be absolute, lest it clobber the app name. */
|
|
37 |
if (filename.charAt(0) == "/") filename = filename.substring(1); |
|
38 |
ajax_call(save_file_as_callback, "fileservice", filename, {}, "POST"); |
|
39 |
}
|
|
40 |
||
41 |
function save_file_as_callback(response) |
|
42 |
{
|
|
43 |
if (response.status == 404 || confirm("Are you sure you want to overwrite " + filename + "?")) |
|
44 |
save_file(filename); |
|
836
by wagrant
Split the editor's Save and Save As functionality. This makes things |
45 |
}
|
46 |
||
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
47 |
/* Return a warning to be used in window.onbeforeunload. */
|
48 |
function confirm_beforeunload() { |
|
49 |
return 'If you continue, any unsaved changes to the current file will be lost.'; |
|
50 |
}
|
|
51 |
||
221
by mattgiuca
editor: Made saving work. |
52 |
function edit_text() |
53 |
{
|
|
778
by mattgiuca
editor.js: The Save button now enables when the text is changed, and disables |
54 |
var savebutton = document.getElementById("save_button"); |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
55 |
savebutton.disabled = false; |
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
56 |
window.onbeforeunload = confirm_beforeunload; |
221
by mattgiuca
editor: Made saving work. |
57 |
}
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
58 |
|
806
by William Grant
www/apps/browser/__init__.py: Display the save widget in actions2 for |
59 |
/** Presents the "editor heading" inserting it into a given element at
|
60 |
* the front. Note that the save widget is handled by the Python.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
61 |
*/
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
62 |
function present_editorhead(elem, path, handler_type) |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
63 |
{
|
777
by mattgiuca
browser: Now hides the "More actions" box altogether if the current file is |
64 |
var div = document.getElementById("actions2"); |
221
by mattgiuca
editor: Made saving work. |
65 |
|
66 |
/* Print a warning message if this is not actually a text file.
|
|
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
67 |
*/
|
68 |
if (handler_type != "text") |
|
69 |
{
|
|
70 |
var warn = dom_make_text_elem("p", |
|
71 |
"Warning: You are editing a binary " + |
|
72 |
"file, which explains any strange characters you may see. If " + |
|
73 |
"you save this file, you could corrupt it."); |
|
74 |
div.appendChild(warn); |
|
75 |
}
|
|
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
76 |
}
|
77 |
||
837
by wagrant
Add a highlighting-language selector to the editor. |
78 |
function highlighting_changed(select) |
79 |
{
|
|
80 |
editbox.edit(editbox.getCode(), select.value); |
|
81 |
}
|
|
82 |
||
866
by wagrant
browser: Only disable the save button on the first load of the editor. |
83 |
function initialise_codepress() |
84 |
{
|
|
85 |
editbox.addChangeHandler(edit_text); |
|
998
by wagrant
editor: Add a hook to CodePress to catch Ctrl+S. Use that to trigger |
86 |
editbox.addSaveHandler(function() {document.getElementById("save_button").click()}); |
866
by wagrant
browser: Only disable the save button on the first load of the editor. |
87 |
|
88 |
/* We can only safely disable the save button on the first load.
|
|
89 |
* Syntax highlighting changes will also get this function called.
|
|
90 |
* We unfortunately need the change handler added each time.
|
|
91 |
*/
|
|
92 |
if (!initialise_codepress.already) |
|
93 |
{
|
|
94 |
disable_save_if_safe(); |
|
95 |
initialise_codepress.already = true; |
|
96 |
}
|
|
97 |
}
|
|
98 |
||
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
99 |
/** Presents the text editor.
|
100 |
*/
|
|
101 |
function handle_text(path, text, handler_type) |
|
102 |
{
|
|
103 |
/* Create a textarea with the text in it
|
|
104 |
* (The makings of a primitive editor).
|
|
105 |
*/
|
|
106 |
var files = document.getElementById("filesbody"); |
|
107 |
/* Put our UI at the top */
|
|
108 |
present_editorhead(files, path, handler_type); |
|
109 |
||
110 |
var div = document.createElement("div"); |
|
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
111 |
div.style.height = '100%'; |
384
by mattgiuca
editor.js: Rewrote the way the editor and surrounding UI are inserted. The top |
112 |
files.appendChild(div); |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
113 |
var txt_elem = dom_make_text_elem("textarea", |
114 |
text.toString()) |
|
115 |
div.appendChild(txt_elem); |
|
116 |
txt_elem.setAttribute("id", "editbox"); |
|
837
by wagrant
Add a highlighting-language selector to the editor. |
117 |
language = language_from_mime(current_file.type); |
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
118 |
|
119 |
// Assume plaintext if no type can be determined.
|
|
837
by wagrant
Add a highlighting-language selector to the editor. |
120 |
language = language ? language : "text"; |
121 |
document.getElementById("highlighting_select").value = language; |
|
122 |
||
967
by wagrant
browser: Turn off CodePress' autocomplete functionality. |
123 |
txt_elem.className = "codepress autocomplete-off " + language; |
221
by mattgiuca
editor: Made saving work. |
124 |
txt_elem.setAttribute("onchange", "edit_text()"); |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
125 |
/* TODO: Make CSS height: 100% work */
|
254
by mattgiuca
editor.js: Extended edit box to 35 lines (was too small). |
126 |
txt_elem.setAttribute("rows", "35"); |
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
127 |
CodePress.run(); |
233
by mattgiuca
Added a shaky implementation of EditArea as the text editor. |
128 |
|
856
by wagrant
editor.js: Prompt before allowing users to navigate away from a |
129 |
window.onbeforeunload = confirm_beforeunload; |
130 |
||
809
by William Grant
Merge killall-editarea branch. We now use CodePress instead, which is |
131 |
/* And set a callback so we know that the editor iframe is loaded so we
|
132 |
* can set a callback so we know when to enable the save button.
|
|
133 |
* We also take this opportunity to disable the save button, if
|
|
134 |
* the browser is likely to reenable it as needed. */
|
|
866
by wagrant
browser: Only disable the save button on the first load of the editor. |
135 |
editbox.onload = initialise_codepress |
220
by mattgiuca
browser: Removed 3 buttons which didn't do anything. |
136 |
}
|
137 |
||
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
138 |
function language_from_mime(mime) |
139 |
{
|
|
140 |
return {'text/x-python': 'python', |
|
141 |
'application/javascript': 'javascript', |
|
142 |
'text/css': 'css', |
|
143 |
'text/plain': 'text', |
|
144 |
'text/html': 'html', |
|
987
by wagrant
editor: Use HTML highlighting for XML by default. |
145 |
'application/xml': 'html', |
810
by William Grant
Merge another bit of killall-editarea - automatic filetype detection. |
146 |
'application/xhtml+xml': 'html'}[mime]; |
147 |
}
|