Skip to content

Commit

Permalink
fix session.filePath is wrong after saveAs
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Oct 26, 2011
1 parent cfecb2d commit cd97a7b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 49 deletions.
15 changes: 13 additions & 2 deletions chrome/content/ace++/startup.js
Expand Up @@ -705,7 +705,7 @@ exports.launch = function(env, options) {
name: "save",
bindKey: {
win: "Ctrl-S",
mac: "Ctrl-S",
mac: "Command-S",
sender: "editor"
},
exec: function(env) {
Expand All @@ -716,13 +716,24 @@ exports.launch = function(env, options) {
name: "save",
bindKey: {
win: "Ctrl-Shift-S",
mac: "Ctrl-Shift-S",
mac: "Command-Shift-S",
sender: "editor"
},
exec: function(env) {
aceManager.saveFile(env.editor, false)
}
});
canon.addCommand({
name: "load",
bindKey: {
win: "Ctrl-O",
mac: "Command-O",
sender: "editor"
},
exec: function(env) {
aceManager.loadFile(env.editor)
}
});

/**************************** folding commands ***********************************************/
canon.addCommand({
Expand Down
93 changes: 46 additions & 47 deletions chrome/content/aceEditor.js
Expand Up @@ -257,57 +257,56 @@ Firebug.Ace = {
return fp;
},

loadFile: function(editor) {
var result, name, result,
session = editor.session, ext = session.extension,
ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
var fp = this.initFilePicker(session, 'open');

result = fp.show();

if (result == Ci.nsIFilePicker.returnOK) {
session.setValue(readEntireFile(fp.file));
session.setFileInfo(ios.newFileURI(fp.file).spec);
}
},
loadFile: function(editor, doNotUpdateFilePath) {
var result, name, result,
session = editor.session, ext = session.extension,
ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
var fp = this.initFilePicker(session, 'open');

saveFile: function(editor, doNotUseFilePicker) {
var file, name, result, session = editor.session,
ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService),
fp = this.initFilePicker(session, 'save');
result = fp.show();

if (doNotUseFilePicker && session.href) {
try {
file = ios.newURI(session.href, null, null)
.QueryInterface(Ci.nsIFileURL).file;
if (file.exists()) {
result = Ci.nsIFilePicker.returnOK;
fp = {file: file};
}
} catch(e){}
}
if (result == Ci.nsIFilePicker.returnOK) {
session.setValue(readEntireFile(fp.file));
doNotUpdateFilePath || session.setFileInfo(ios.newFileURI(fp.file).spec);
}
},

saveFile: function(editor, doNotUseFilePicker, doNotUpdateFilePath) {
var file, name, result, session = editor.session,
ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService),
fp = this.initFilePicker(session, 'save');

if (doNotUseFilePicker && session.href) {
try {
file = ios.newURI(session.href, null, null)
.QueryInterface(Ci.nsIFileURL).file;
if (file.exists()) {
result = Ci.nsIFilePicker.returnOK;
fp = {file: file};
}
} catch(e){}
}

if (!fp.file)
result = fp.show();
if (result == Ci.nsIFilePicker.returnOK) {
file = fp.file;
name = file.leafName;
if (!fp.file){
result = fp.show();
file = fp.file;
}
if (result == Ci.nsIFilePicker.returnOK) {
name = file.leafName;

if (name.indexOf('.')<0) {
file = file.parent;
file.append(name + '.' + session.extension);
}
if (name.indexOf('.')<0) {
file = file.parent;
file.append(name + '.' + session.extension);
}

writeFile(file, session.getValue());
if (!session.filePath)
session.setFileInfo(ios.newFileURI(file).spec);
}
else if (result == Ci.nsIFilePicker.returnReplace) {
writeFile(fp.file, session.getValue());
if (!session.filePath)
session.setFileInfo(ios.newFileURI(file).spec);
}
},
writeToFile(file, session.getValue());
}
else if (result == Ci.nsIFilePicker.returnReplace) {
writeToFile(file, session.getValue());
}
if (file)
doNotUpdateFilePath || session.setFileInfo(ios.newFileURI(file).spec);
},

savePopupShowing: function(popup) {
FBL.eraseNode(popup)
Expand Down Expand Up @@ -701,7 +700,7 @@ function readEntireFile(file) {
return data;
}

function writeFile(file, text) {
function writeToFile(file, text) {
var fostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream),
converter = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);

Expand Down

0 comments on commit cd97a7b

Please sign in to comment.