Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

After changing encoding of a dirty file if user cancels the popup then encoding of file should not be changed #13497

Merged
merged 3 commits into from
Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions src/editor/EditorStatusBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ define(function (require, exports, module) {
ProjectManager = require("project/ProjectManager"),
Async = require("utils/Async"),
FileSystem = require("filesystem/FileSystem"),
CommandManager = require("command/CommandManager"),
Commands = require("command/Commands"),
DocumentManager = require("document/DocumentManager"),
StringUtils = require("utils/StringUtils");

var SupportedEncodingsText = require("text!supported-encodings.json"),
Expand Down Expand Up @@ -471,38 +474,19 @@ define(function (require, exports, module) {
// Encoding select change handler
encodingSelect.on("select", function (e, encoding) {
var document = EditorManager.getActiveEditor().document,
fullPath = document.file.fullPath;
originalPath = document.file.fullPath,
originalEncoding = document.file._encoding;

document.file._encoding = encoding;


if (!(document.file instanceof InMemoryFile) && document.isDirty) {
var dialogId = DefaultDialogs.DIALOG_ID_EXT_CHANGED,
message = StringUtils.format(
Strings.DIRTY_FILE_ENCODING_CHANGE_WARN,
StringUtils.breakableUrl(
ProjectManager.makeProjectRelativeIfPossible(document.file.fullPath)
)
),
buttons = [
{
className: Dialogs.DIALOG_BTN_CLASS_LEFT,
id: Dialogs.DIALOG_BTN_DONTSAVE,
text: Strings.IGNORE_RELOAD_FROM_DISK
},
{
className: Dialogs.DIALOG_BTN_CLASS_PRIMARY,
id: Dialogs.DIALOG_BTN_CANCEL,
text: Strings.CANCEL
}
];

Dialogs.showModalDialog(dialogId, Strings.SAVE_FILE_ENCODING_CHANGE_WARN, message, buttons)
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_DONTSAVE) {
_changeEncodingAndReloadDoc(document);
}
});
CommandManager.execute(Commands.FILE_SAVE_AS, {doc: document}).done(function () {
var doc = DocumentManager.getCurrentDocument();
if (originalPath === doc.file.fullPath) {
_changeEncodingAndReloadDoc(doc);
} else {
document.file._encoding = originalEncoding;
}
});
} else if (document.file instanceof InMemoryFile) {
encodingSelect.$button.text(encoding);
} else if (!document.isDirty) {
Expand Down
3 changes: 0 additions & 3 deletions src/nls/fr/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ define({
"EXT_MODIFIED_WARNING": "<span class='dialog-filename'>{0}</span> a été modifié sur le disque, dans une application autre que {APP_NAME}.<br /><br />Voulez-vous enregistrer le fichier et remplacer ces modifications ?",
"EXT_MODIFIED_MESSAGE": "Le fichier <span class='dialog-filename'>{0}</span> a été modifié sur le disque dans une autre application que {APP_NAME} mais présente également des modifications non enregistrées dans {APP_NAME}.<br /><br />Quelle version souhaitez-vous conserver ?",
"EXT_DELETED_MESSAGE": "Le fichier <span class='dialog-filename'>{0}</span> a été supprimé du disque dans une autre application que {APP_NAME} mais présente également des modifications non enregistrées dans {APP_NAME}.<br /><br />Souhaitez-vous conserver vos modifications ?",
"DIRTY_FILE_ENCODING_CHANGE_WARN": "Impossible de modifier le codage d’un fichier sale",
"IGNORE_RELOAD_FROM_DISK": "Ignorer les modifications et recharger depuis le disque",
"SAVE_FILE_ENCODING_CHANGE_WARN": "Enregistrer le fichier avant de modifier le codage",

// Generic dialog/button labels
"DONE": "Terminé",
Expand Down
3 changes: 0 additions & 3 deletions src/nls/ja/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ define({
"EXT_MODIFIED_WARNING": "<span class='dialog-filename'>{0}</span> は {APP_NAME} 外のディスク上で変更されています。<br /><br />ファイルを保存し、これらの変更を上書きしますか?",
"EXT_MODIFIED_MESSAGE": "<span class='dialog-filename'>{0}</span> は {APP_NAME} 外のディスク上で変更されていますが、{APP_NAME} 内にも保存されていない変更があります。<br /><br />どちらのバージョンを保持しますか?",
"EXT_DELETED_MESSAGE": "<span class='dialog-filename'>{0}</span> は {APP_NAME} 外のディスク上で削除されていますが、{APP_NAME} 内に保存されていない変更があります。<br /><br />変更を保持しますか?",
"DIRTY_FILE_ENCODING_CHANGE_WARN": "ダーティファイルのエンコードを変更できません",
"IGNORE_RELOAD_FROM_DISK": "変更を無視してディスクから再読み込み",
"SAVE_FILE_ENCODING_CHANGE_WARN": "エンコードする前にファイルを保存",

// Generic dialog/button labels
"DONE": "完了",
Expand Down
3 changes: 0 additions & 3 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ define({
"EXT_MODIFIED_WARNING" : "<span class='dialog-filename'>{0}</span> has been modified on disk outside of {APP_NAME}.<br /><br />Do you want to save the file and overwrite those changes?",
"EXT_MODIFIED_MESSAGE" : "<span class='dialog-filename'>{0}</span> has been modified on disk outside of {APP_NAME}, but also has unsaved changes in {APP_NAME}.<br /><br />Which version do you want to keep?",
"EXT_DELETED_MESSAGE" : "<span class='dialog-filename'>{0}</span> has been deleted on disk outside of {APP_NAME}, but has unsaved changes in {APP_NAME}.<br /><br />Do you want to keep your changes?",
"DIRTY_FILE_ENCODING_CHANGE_WARN" : "Cannot change encoding of a dirty file",
"IGNORE_RELOAD_FROM_DISK" : "Ignore changes and reload from disk",
"SAVE_FILE_ENCODING_CHANGE_WARN" : "Save the file before changing encoding",

// Generic dialog/button labels
"DONE" : "Done",
Expand Down