Show More
@@ -31,6 +31,7 b' function($,' | |||||
31 | this.file_path = options.file_path; |
|
31 | this.file_path = options.file_path; | |
32 | this.config = options.config; |
|
32 | this.config = options.config; | |
33 | this.codemirror = new CodeMirror($(this.selector)[0]); |
|
33 | this.codemirror = new CodeMirror($(this.selector)[0]); | |
|
34 | this.generation = -1; | |||
34 |
|
35 | |||
35 | // It appears we have to set commands on the CodeMirror class, not the |
|
36 | // It appears we have to set commands on the CodeMirror class, not the | |
36 | // instance. I'd like to be wrong, but since there should only be one CM |
|
37 | // instance. I'd like to be wrong, but since there should only be one CM | |
@@ -79,6 +80,7 b' function($,' | |||||
79 | cm.setOption('mode', mode); |
|
80 | cm.setOption('mode', mode); | |
80 | }); |
|
81 | }); | |
81 | that.save_enabled = true; |
|
82 | that.save_enabled = true; | |
|
83 | that.generation = cm.changeGeneration(); | |||
82 | }, |
|
84 | }, | |
83 | function(error) { |
|
85 | function(error) { | |
84 | cm.setValue("Error! " + error.message + |
|
86 | cm.setValue("Error! " + error.message + | |
@@ -101,6 +103,8 b' function($,' | |||||
101 | content: this.codemirror.getValue(), |
|
103 | content: this.codemirror.getValue(), | |
102 | }; |
|
104 | }; | |
103 | var that = this; |
|
105 | var that = this; | |
|
106 | // record change generation for isClean | |||
|
107 | this.generation = this.codemirror.changeGeneration(); | |||
104 | return this.contents.save(this.file_path, model).then(function() { |
|
108 | return this.contents.save(this.file_path, model).then(function() { | |
105 | that.events.trigger("save_succeeded.TextEditor"); |
|
109 | that.events.trigger("save_succeeded.TextEditor"); | |
106 | }); |
|
110 | }); |
@@ -19,7 +19,7 b' require([' | |||||
19 | events, |
|
19 | events, | |
20 | contents, |
|
20 | contents, | |
21 | configmod, |
|
21 | configmod, | |
22 |
edit |
|
22 | editmod, | |
23 | menubar, |
|
23 | menubar, | |
24 | notificationarea |
|
24 | notificationarea | |
25 | ){ |
|
25 | ){ | |
@@ -28,10 +28,10 b' require([' | |||||
28 | var base_url = utils.get_body_data('baseUrl'); |
|
28 | var base_url = utils.get_body_data('baseUrl'); | |
29 | var file_path = utils.get_body_data('filePath'); |
|
29 | var file_path = utils.get_body_data('filePath'); | |
30 | contents = new contents.Contents({base_url: base_url}); |
|
30 | contents = new contents.Contents({base_url: base_url}); | |
31 | var config = new configmod.ConfigSection('edit', {base_url: base_url}) |
|
31 | var config = new configmod.ConfigSection('edit', {base_url: base_url}); | |
32 | config.load(); |
|
32 | config.load(); | |
33 |
|
33 | |||
34 |
var editor = new edit |
|
34 | var editor = new editmod.Editor('#texteditor-container', { | |
35 | base_url: base_url, |
|
35 | base_url: base_url, | |
36 | events: events, |
|
36 | events: events, | |
37 | contents: contents, |
|
37 | contents: contents, | |
@@ -63,4 +63,11 b' require([' | |||||
63 | }); |
|
63 | }); | |
64 | editor.load(); |
|
64 | editor.load(); | |
65 | page.show(); |
|
65 | page.show(); | |
|
66 | ||||
|
67 | window.onbeforeunload = function () { | |||
|
68 | if (!editor.codemirror.isClean(editor.generation)) { | |||
|
69 | return "Unsaved changes will be lost. Close anyway?"; | |||
|
70 | } | |||
|
71 | }; | |||
|
72 | ||||
66 | }); |
|
73 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now