This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[ARCH] Improving the Dialog API #3086
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c9ca76b
Improving the Dialog API
TomMalbran e95df02
Reversing the buttons order
TomMalbran a58515b
Merged with master. Fixed conflict issues.
TomMalbran 064b108
Updates to address the review comments
TomMalbran f37ebd0
JSHint indentation fixes
TomMalbran bd08117
Fixes after review
TomMalbran d2e8b02
Merge with master
TomMalbran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,10 @@ define(function (require, exports, module) { | |
var AppInit = require("utils/AppInit"), | ||
CommandManager = require("command/CommandManager"), | ||
Commands = require("command/Commands"), | ||
KeyBindingManager = require("command/KeyBindingManager"), | ||
NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem, | ||
ProjectManager = require("project/ProjectManager"), | ||
DocumentManager = require("document/DocumentManager"), | ||
EditorManager = require("editor/EditorManager"), | ||
FileViewController = require("project/FileViewController"), | ||
FileUtils = require("file/FileUtils"), | ||
StringUtils = require("utils/StringUtils"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This 2 modules aren't required anymore so I removed them. |
||
Async = require("utils/Async"), | ||
|
@@ -209,8 +207,6 @@ define(function (require, exports, module) { | |
// Prompt the user with a dialog | ||
NativeFileSystem.showOpenDialog(true, false, Strings.OPEN_FILE, _defaultOpenDialogFullPath, | ||
null, function (paths) { | ||
var i; | ||
|
||
if (paths.length > 0) { | ||
// Add all files to the working set without verifying that | ||
// they still exist on disk (for faster opening) | ||
|
@@ -401,7 +397,7 @@ define(function (require, exports, module) { | |
|
||
function handleError(error, fileEntry) { | ||
showSaveFileError(error.name, fileEntry.fullPath) | ||
.always(function () { | ||
.done(function () { | ||
result.reject(error); | ||
}); | ||
} | ||
|
@@ -581,36 +577,42 @@ define(function (require, exports, module) { | |
StringUtils.format( | ||
Strings.SAVE_CLOSE_MESSAGE, | ||
StringUtils.breakableUrl(filename) | ||
) | ||
).done(function (id) { | ||
if (id === Dialogs.DIALOG_BTN_CANCEL) { | ||
result.reject(); | ||
} else if (id === Dialogs.DIALOG_BTN_OK) { | ||
// "Save" case: wait until we confirm save has succeeded before closing | ||
doSave(doc) | ||
.done(function () { | ||
doClose(file); | ||
result.resolve(); | ||
}) | ||
.fail(function () { | ||
result.reject(); | ||
}); | ||
} else { | ||
// "Don't Save" case: even though we're closing the main editor, other views of | ||
// the Document may remain in the UI. So we need to revert the Document to a clean | ||
// copy of whatever's on disk. | ||
doClose(file); | ||
|
||
// Only reload from disk if we've executed the Close for real, | ||
// *and* if at least one other view still exists | ||
if (!promptOnly && DocumentManager.getOpenDocumentForPath(file.fullPath)) { | ||
doRevert(doc) | ||
.pipe(result.resolve, result.reject); | ||
), | ||
[ | ||
{ className: "left", id: "dontsave", text: Strings.DONT_SAVE }, | ||
{ className: "", id: "cancel", text: Strings.CANCEL }, | ||
{ className: "primary", id: "ok", text: Strings.SAVE } | ||
] | ||
) | ||
.done(function (id) { | ||
if (id === Dialogs.DIALOG_BTN_CANCEL) { | ||
result.reject(); | ||
} else if (id === Dialogs.DIALOG_BTN_OK) { | ||
// "Save" case: wait until we confirm save has succeeded before closing | ||
doSave(doc) | ||
.done(function () { | ||
doClose(file); | ||
result.resolve(); | ||
}) | ||
.fail(function () { | ||
result.reject(); | ||
}); | ||
} else { | ||
result.resolve(); | ||
// "Don't Save" case: even though we're closing the main editor, other views of | ||
// the Document may remain in the UI. So we need to revert the Document to a clean | ||
// copy of whatever's on disk. | ||
doClose(file); | ||
|
||
// Only reload from disk if we've executed the Close for real, | ||
// *and* if at least one other view still exists | ||
if (!promptOnly && DocumentManager.getOpenDocumentForPath(file.fullPath)) { | ||
doRevert(doc) | ||
.pipe(result.resolve, result.reject); | ||
} else { | ||
result.resolve(); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
result.always(function () { | ||
EditorManager.focusEditor(); | ||
}); | ||
|
@@ -673,22 +675,28 @@ define(function (require, exports, module) { | |
Dialogs.showModalDialog( | ||
Dialogs.DIALOG_ID_SAVE_CLOSE, | ||
Strings.SAVE_CLOSE_TITLE, | ||
message | ||
).done(function (id) { | ||
if (id === Dialogs.DIALOG_BTN_CANCEL) { | ||
result.reject(); | ||
} else if (id === Dialogs.DIALOG_BTN_OK) { | ||
// Save all unsaved files, then if that succeeds, close all | ||
saveAll().done(function () { | ||
result.resolve(); | ||
}).fail(function () { | ||
message, | ||
[ | ||
{ className: "left", id: "dontsave", text: Strings.DONT_SAVE }, | ||
{ className: "", id: "cancel", text: Strings.CANCEL }, | ||
{ className: "primary", id: "ok", text: Strings.SAVE } | ||
] | ||
) | ||
.done(function (id) { | ||
if (id === Dialogs.DIALOG_BTN_CANCEL) { | ||
result.reject(); | ||
}); | ||
} else { | ||
// "Don't Save" case--we can just go ahead and close all files. | ||
result.resolve(); | ||
} | ||
}); | ||
} else if (id === Dialogs.DIALOG_BTN_OK) { | ||
// Save all unsaved files, then if that succeeds, close all | ||
saveAll().done(function () { | ||
result.resolve(); | ||
}).fail(function () { | ||
result.reject(); | ||
}); | ||
} else { | ||
// "Don't Save" case--we can just go ahead and close all files. | ||
result.resolve(); | ||
} | ||
}); | ||
} | ||
|
||
// If all the unsaved-changes confirmations pan out above, then go ahead & close all editors | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 1 addition & 23 deletions
24
src/extensions/samples/LocalizationExample/htmlContent/sampleHTMLFragment.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<div class="{{dlgClass}} template modal"> | ||
<div class="modal-header"> | ||
<a href="#" class="close">×</a> | ||
<h1 class="dialog-title">{{{title}}}</h1> | ||
</div> | ||
<div class="modal-body"> | ||
<p class="dialog-message">{{{message}}}</p> | ||
</div> | ||
<div class="modal-footer"> | ||
{{#buttons}} | ||
<button class="dialog-button btn {{className}}" data-button-id="{{id}}">{{{text}}}</button> | ||
{{/buttons}} | ||
</div> | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The button ids should be
Dialogs.DIALOG_BTN_***
constants instead of hard-coded strings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Do you think we should use constants for the class names too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, having constants for the class names sounds good.