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

[ARCH] Improving the Dialog API #3086

Merged
merged 7 commits into from
May 28, 2013
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
69 changes: 40 additions & 29 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ define(function LiveDevelopment(require, exports, module) {

var Async = require("utils/Async"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
DocumentManager = require("document/DocumentManager"),
EditorManager = require("editor/EditorManager"),
FileUtils = require("file/FileUtils"),
Expand Down Expand Up @@ -600,7 +601,7 @@ define(function LiveDevelopment(require, exports, module) {

function showWrongDocError() {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
DefaultDialogs.DIALOG_ID_ERROR,
Strings.LIVE_DEVELOPMENT_ERROR_TITLE,
Strings.LIVE_DEV_NEED_HTML_MESSAGE
);
Expand All @@ -617,15 +618,12 @@ define(function LiveDevelopment(require, exports, module) {
} else {
result.reject();
}
})
.fail(function () {
result.reject();
});
}

function showLiveDevServerNotReadyError() {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
DefaultDialogs.DIALOG_ID_ERROR,
Strings.LIVE_DEVELOPMENT_ERROR_TITLE,
Strings.LIVE_DEV_SERVER_NOT_READY_MESSAGE
);
Expand All @@ -647,30 +645,43 @@ define(function LiveDevelopment(require, exports, module) {
if (retryCount > 6) {
_setStatus(STATUS_ERROR);
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_LIVE_DEVELOPMENT,
DefaultDialogs.DIALOG_ID_LIVE_DEVELOPMENT,
Strings.LIVE_DEVELOPMENT_RELAUNCH_TITLE,
Strings.LIVE_DEVELOPMENT_ERROR_MESSAGE
).done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK) {
// User has chosen to reload Chrome, quit the running instance
_setStatus(STATUS_INACTIVE);
NativeApp.closeLiveBrowser()
.done(function () {
browserStarted = false;
window.setTimeout(function () {
open().done(result.resolve).fail(result.reject);
Strings.LIVE_DEVELOPMENT_ERROR_MESSAGE,
[
{
className: Dialogs.DIALOG_BTN_CLASS_LEFT,
id: Dialogs.DIALOG_BTN_CANCEL,
text: Strings.CANCEL
},
{
className: Dialogs.DIALOG_BTN_CLASS_PRIMARY,
id: Dialogs.DIALOG_BTN_OK,
text: Strings.RELAUNCH_CHROME
}
]
)
.done(function (id) {
if (id === Dialogs.DIALOG_BTN_OK) {
// User has chosen to reload Chrome, quit the running instance
_setStatus(STATUS_INACTIVE);
NativeApp.closeLiveBrowser()
.done(function () {
browserStarted = false;
window.setTimeout(function () {
open().done(result.resolve).fail(result.reject);
});
})
.fail(function (err) {
// Report error?
_setStatus(STATUS_ERROR);
browserStarted = false;
result.reject("CLOSE_LIVE_BROWSER");
});
})
.fail(function (err) {
// Report error?
_setStatus(STATUS_ERROR);
browserStarted = false;
result.reject("CLOSE_LIVE_BROWSER");
});
} else {
result.reject("CANCEL");
}
});
} else {
result.reject("CANCEL");
}
});
return;
}
retryCount++;
Expand Down Expand Up @@ -699,7 +710,7 @@ define(function LiveDevelopment(require, exports, module) {
}

Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_LAUNCHING_BROWSER_TITLE,
message
);
Expand Down Expand Up @@ -872,7 +883,7 @@ define(function LiveDevelopment(require, exports, module) {
.fail(function () {
close();
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
DefaultDialogs.DIALOG_ID_ERROR,
Strings.LIVE_DEVELOPMENT_ERROR_TITLE,
Strings.LIVE_DEV_LOADING_ERROR_MESSAGE
);
Expand Down
3 changes: 2 additions & 1 deletion src/LiveDevelopment/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ define(function main(require, exports, module) {
CommandManager = require("command/CommandManager"),
PreferencesManager = require("preferences/PreferencesManager"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
UrlParams = require("utils/UrlParams").UrlParams,
Strings = require("strings"),
ExtensionUtils = require("utils/ExtensionUtils"),
Expand Down Expand Up @@ -120,7 +121,7 @@ define(function main(require, exports, module) {
if (!params.get("skipLiveDevelopmentInfo") && !prefs.getValue("afterFirstLaunch")) {
prefs.setValue("afterFirstLaunch", "true");
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_INFO,
DefaultDialogs.DIALOG_ID_INFO,
Strings.LIVE_DEVELOPMENT_INFO_TITLE,
Strings.LIVE_DEVELOPMENT_INFO_MESSAGE
).done(function (id) {
Expand Down
3 changes: 2 additions & 1 deletion src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ define(function (require, exports, module) {
MainViewHTML = require("text!htmlContent/main-view.html"),
Strings = require("strings"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
ExtensionLoader = require("utils/ExtensionLoader"),
SidebarView = require("project/SidebarView"),
Async = require("utils/Async"),
Expand Down Expand Up @@ -165,7 +166,7 @@ define(function (require, exports, module) {
// Let the user know Brackets doesn't run in a web browser yet
if (brackets.inBrowser) {
Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_IN_BROWSER_TITLE,
Strings.ERROR_IN_BROWSER
);
Expand Down
148 changes: 94 additions & 54 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ 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"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
Strings = require("strings"),
PreferencesManager = require("preferences/PreferencesManager"),
PerfUtils = require("utils/PerfUtils"),
Expand Down Expand Up @@ -209,8 +208,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)
Expand Down Expand Up @@ -383,9 +380,16 @@ define(function (require, exports, module) {
_handleNewItemInProject(true);
}

function showSaveFileError(name, path) {
/**
* @private
* Shows an Error modal dialog
* @param {string} name
* @param {string} path
* @return {Dialog}
*/
function _showSaveFileError(name, path) {
return Dialogs.showModalDialog(
Dialogs.DIALOG_ID_ERROR,
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_SAVING_FILE_TITLE,
StringUtils.format(
Strings.ERROR_SAVING_FILE,
Expand All @@ -400,8 +404,8 @@ define(function (require, exports, module) {
var result = new $.Deferred();

function handleError(error, fileEntry) {
showSaveFileError(error.name, fileEntry.fullPath)
.always(function () {
_showSaveFileError(error.name, fileEntry.fullPath)
.done(function () {
result.reject(error);
});
}
Expand Down Expand Up @@ -517,7 +521,7 @@ define(function (require, exports, module) {
})
.fail(function (error) {
FileUtils.showFileOpenError(error.name, doc.file.fullPath)
.always(function () {
.done(function () {
result.reject(error);
});
});
Expand Down Expand Up @@ -576,41 +580,59 @@ define(function (require, exports, module) {
var filename = PathUtils.parseUrl(doc.file.fullPath).filename;

Dialogs.showModalDialog(
Dialogs.DIALOG_ID_SAVE_CLOSE,
DefaultDialogs.DIALOG_ID_SAVE_CLOSE,
Strings.SAVE_CLOSE_TITLE,
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 : Dialogs.DIALOG_BTN_CLASS_LEFT,
id : Dialogs.DIALOG_BTN_DONTSAVE,
text : Strings.DONT_SAVE
},
{
className : Dialogs.DIALOG_BTN_CLASS_NORMAL,
id : Dialogs.DIALOG_BTN_CANCEL,
text : Strings.CANCEL
},
{
className : Dialogs.DIALOG_BTN_CLASS_PRIMARY,
id : Dialogs.DIALOG_BTN_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();
});
Expand Down Expand Up @@ -671,24 +693,42 @@ define(function (require, exports, module) {
message += "</ul>";

Dialogs.showModalDialog(
Dialogs.DIALOG_ID_SAVE_CLOSE,
DefaultDialogs.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 : Dialogs.DIALOG_BTN_CLASS_LEFT,
id : Dialogs.DIALOG_BTN_DONTSAVE,
text : Strings.DONT_SAVE
},
{
className : Dialogs.DIALOG_BTN_CLASS_NORMAL,
id : Dialogs.DIALOG_BTN_CANCEL,
text : Strings.CANCEL
},
{
className : Dialogs.DIALOG_BTN_CLASS_PRIMARY,
id : Dialogs.DIALOG_BTN_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
Expand Down
2 changes: 1 addition & 1 deletion src/extensibility/ExtensionManagerDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define(function (require, exports, module) {
// Open the dialog.
Dialogs.showModalDialogUsingTemplate(
Mustache.render(dialogTemplate, Strings)
).always(function () {
).done(function () {
view.dispose();
});

Expand Down
Loading