Commit bcf067ad authored by Alain Takoudjou's avatar Alain Takoudjou

Editor: Fix mark tab as modified after loading file

parent 8c2b8ad3
...@@ -11,7 +11,7 @@ $(document).ready(function () { ...@@ -11,7 +11,7 @@ $(document).ready(function () {
config, config,
files, files,
working_node = null, working_node = null,
editorlist = Array(), editorlist = [],
editorIndex = 0, editorIndex = 0,
saveTimeOut = null, saveTimeOut = null,
softwareDisplay = true, softwareDisplay = true,
...@@ -23,7 +23,7 @@ $(document).ready(function () { ...@@ -23,7 +23,7 @@ $(document).ready(function () {
ajaxResult = false, ajaxResult = false,
clipboardNode = null, clipboardNode = null,
pasteMode = null, pasteMode = null,
favourite_list = new Array(), favourite_list = [],
editorWidth = $("#code").css("width"), editorWidth = $("#code").css("width"),
beforeunload_warning_set = 0, beforeunload_warning_set = 0,
base_path = function () { base_path = function () {
...@@ -65,11 +65,12 @@ $(document).ready(function () { ...@@ -65,11 +65,12 @@ $(document).ready(function () {
.done(function(data) { .done(function(data) {
var editor = editorlist[hash].editor; var editor = editorlist[hash].editor;
if (data.code === 1) { if (data.code === 1) {
editor.getSession().setValue(data.result); editor.session.setValue(data.result);
$(activeSpan).html(file.replace(/^.*(\\|\/|\:)/, '')); $(activeSpan).html(file.replace(/^.*(\\|\/|\:)/, ''));
var mode = modelist.getModeForPath(file); var mode = modelist.getModeForPath(file);
editor.getSession().modeName = mode.name; editor.session.modeName = mode.name;
editor.getSession().setMode(mode.mode); editor.session.setMode(mode.mode);
editor.session.getUndoManager().reset();
editorlist[hash].busy = false; editorlist[hash].busy = false;
status = true; status = true;
} else { } else {
...@@ -103,7 +104,7 @@ $(document).ready(function () { ...@@ -103,7 +104,7 @@ $(document).ready(function () {
url: $SCRIPT_ROOT + '/saveFileContent', url: $SCRIPT_ROOT + '/saveFileContent',
data: { data: {
file: editorlist[hash].path, file: editorlist[hash].path,
content: editorlist[hash].editor.getSession().getValue() content: editorlist[hash].editor.session.getValue()
}}) }})
.done(function(data) { .done(function(data) {
if (data.code === 1) { if (data.code === 1) {
...@@ -123,6 +124,7 @@ $(document).ready(function () { ...@@ -123,6 +124,7 @@ $(document).ready(function () {
}) })
.always(function() { .always(function() {
editorlist[hash].busy = false; editorlist[hash].busy = false;
editorlist[hash].editor.session.getUndoManager().markClean();
}); });
} }
...@@ -156,7 +158,7 @@ $(document).ready(function () { ...@@ -156,7 +158,7 @@ $(document).ready(function () {
if (addTab) { if (addTab) {
numberTab++; numberTab++;
} }
if (numberTab == 0) { if (numberTab === 0) {
return width; return width;
} }
var tabBarWidth = $(".box_header").width() - $(".box_header ul").width(); var tabBarWidth = $(".box_header").width() - $(".box_header ul").width();
...@@ -274,16 +276,19 @@ $(document).ready(function () { ...@@ -274,16 +276,19 @@ $(document).ready(function () {
//Init Ace editor!! //Init Ace editor!!
editor.setTheme("ace/theme/crimson_editor"); editor.setTheme("ace/theme/crimson_editor");
editor.getSession().setMode("ace/mode/text"); editor.session.setMode("ace/mode/text");
editor.getSession().setTabSize(2); editor.session.setTabSize(2);
editor.getSession().setUseSoftTabs(true); editor.session.setUseSoftTabs(true);
editor.renderer.setHScrollBarAlwaysVisible(false); editor.renderer.setHScrollBarAlwaysVisible(false);
editorlist[hash] = {editor: editor, changed: false, path: path, editorlist[hash] = {editor: editor, changed: false, path: path,
isOpened: false, busy: true}; isOpened: false, busy: true};
editor.on("change", function (e) { editor.on('input', function (e) {
var activeToken = getActiveToken(), var activeToken = getActiveToken(),
activeSpan = getActiveTabTitleSelector(); activeSpan = getActiveTabTitleSelector();
if (editorlist[activeToken].editor.session.getUndoManager().isClean()){
return;
}
if (!editorlist[activeToken].busy && !editorlist[activeToken].changed) { if (!editorlist[activeToken].busy && !editorlist[activeToken].changed) {
editorlist[activeToken].changed = true; editorlist[activeToken].changed = true;
$(activeSpan).html("*" + $(activeSpan).html()); $(activeSpan).html("*" + $(activeSpan).html());
...@@ -482,7 +487,7 @@ $(document).ready(function () { ...@@ -482,7 +487,7 @@ $(document).ready(function () {
} }
break; break;
} }
}; }
function manageMenu (srcElement, menu){ function manageMenu (srcElement, menu){
/*if (!srcElement.hasClass('fancytree-node')){ /*if (!srcElement.hasClass('fancytree-node')){
...@@ -551,21 +556,21 @@ $(document).ready(function () { ...@@ -551,21 +556,21 @@ $(document).ready(function () {
data: {opt: 9, filename: node.title, dir: directory}, data: {opt: 9, filename: node.title, dir: directory},
success: function (data) { success: function (data) {
$("#inline_content").empty(); $("#inline_content").empty();
$("#inline_content").append('<div class="main_content"><pre id="editorViewer"></pre></div>'); $("#inline_content").append('<div class="main_content"><pre id="editorViewer"></pre></div>');
viewer = ace.edit("editorViewer"); viewer = ace.edit("editorViewer");
viewer.setTheme("ace/theme/crimson_editor"); viewer.setTheme("ace/theme/crimson_editor");
var mode = modelist.getModeForPath(node.data.path); var mode = modelist.getModeForPath(node.data.path);
viewer.getSession().modeName = mode.name; viewer.session.modeName = mode.name;
viewer.getSession().setMode(mode.mode); viewer.session.setMode(mode.mode);
viewer.getSession().setTabSize(2); viewer.session.setTabSize(2);
viewer.getSession().setUseSoftTabs(true); viewer.session.setUseSoftTabs(true);
viewer.renderer.setHScrollBarAlwaysVisible(false); viewer.renderer.setHScrollBarAlwaysVisible(false);
viewer.setReadOnly(true); viewer.setReadOnly(true);
$("#inlineViewer").colorbox({inline:true, width: "847px", onComplete:function(){ $("#inlineViewer").colorbox({inline:true, width: "847px", onComplete:function(){
viewer.getSession().setValue(data); viewer.session.setValue(data);
}, title: "Content of file: " + node.title}); }, title: "Content of file: " + node.title});
$("#inlineViewer").click(); $("#inlineViewer").click();
} }
}); });
break; break;
...@@ -578,7 +583,7 @@ $(document).ready(function () { ...@@ -578,7 +583,7 @@ $(document).ready(function () {
break; break;
case "nfolder": case "nfolder":
var newName = window.prompt('Please Enter the folder name: '); var newName = window.prompt('Please Enter the folder name: ');
if (newName == null || newName.length < 1) { if (newName === null || newName.length < 1) {
return; return;
} }
var dataForSend = { var dataForSend = {
...@@ -596,7 +601,7 @@ $(document).ready(function () { ...@@ -596,7 +601,7 @@ $(document).ready(function () {
break; break;
case "nfile": case "nfile":
var newName = window.prompt('Please Enter the file name: '); var newName = window.prompt('Please Enter the file name: ');
if (newName == null || newName.length < 1) { if (newName === null || newName.length < 1) {
return; return;
} }
var dataForSend = { var dataForSend = {
...@@ -675,7 +680,7 @@ $(document).ready(function () { ...@@ -675,7 +680,7 @@ $(document).ready(function () {
return; return;
} }
}, manageMenu); }, manageMenu);
}; }
// --- Init fancytree during startup ---------------------------------------- // --- Init fancytree during startup ----------------------------------------
function initTree(tree, path, key){ function initTree(tree, path, key){
...@@ -963,7 +968,7 @@ $(document).ready(function () { ...@@ -963,7 +968,7 @@ $(document).ready(function () {
return false; return false;
} }
config.loadModule("ace/ext/searchbox", function(e) { config.loadModule("ace/ext/searchbox", function(e) {
e.Search(getCurrentEditor()) e.Search(getCurrentEditor());
}); });
$("#option").click(); $("#option").click();
return false; return false;
...@@ -974,7 +979,7 @@ $(document).ready(function () { ...@@ -974,7 +979,7 @@ $(document).ready(function () {
return false; return false;
} }
config.loadModule("ace/ext/searchbox", function(e) { config.loadModule("ace/ext/searchbox", function(e) {
e.Search(getCurrentEditor(), true) e.Search(getCurrentEditor(), true);
}); });
$("#option").click(); $("#option").click();
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment