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

Remove some circular dependencies #10641

Merged
merged 1 commit into from
Mar 6, 2015
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
24 changes: 7 additions & 17 deletions src/LiveDevelopment/LiveDevMultiBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ define(function (require, exports, module) {
ProjectManager = require("project/ProjectManager"),
Strings = require("strings"),
_ = require("thirdparty/lodash"),
LiveDevelopmentUtils = require("LiveDevelopment/LiveDevelopmentUtils"),
LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"),
NodeSocketTransport = require("LiveDevelopment/MultiBrowserImpl/transports/NodeSocketTransport"),
LiveDevProtocol = require("LiveDevelopment/MultiBrowserImpl/protocol/LiveDevProtocol"),
Expand Down Expand Up @@ -120,17 +121,6 @@ define(function (require, exports, module) {
* @type {BaseServer}
*/
var _server;

/**
* @private
* Returns true if we think the given extension is for an HTML file.
* @param {string} ext The extension to check.
* @return {boolean} true if this is an HTML extension
*/
function _isHtmlFileExt(ext) {
return (FileUtils.isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
}

/**
* @private
Expand All @@ -143,7 +133,7 @@ define(function (require, exports, module) {
return LiveCSSDocument;
}

if (_isHtmlFileExt(doc.file.fullPath)) {
if (LiveDevelopmentUtils.isHtmlFileExt(doc.file.fullPath)) {
return LiveHTMLDocument;
}

Expand Down Expand Up @@ -368,7 +358,7 @@ define(function (require, exports, module) {
// Is the currently opened document already a file we can use for Live Development?
if (doc) {
refPath = doc.file.fullPath;
if (FileUtils.isStaticHtmlFileExt(refPath) || FileUtils.isServerHtmlFileExt(refPath)) {
if (LiveDevelopmentUtils.isStaticHtmlFileExt(refPath) || LiveDevelopmentUtils.isServerHtmlFileExt(refPath)) {
return new $.Deferred().resolve(doc);
}
}
Expand Down Expand Up @@ -400,11 +390,11 @@ define(function (require, exports, module) {
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
if (FileUtils.getFilenameWithoutExtension(fileInfo.name) === "index") {
if (hasOwnServerForLiveDevelopment) {
if ((FileUtils.isServerHtmlFileExt(fileInfo.name)) ||
(FileUtils.isStaticHtmlFileExt(fileInfo.name))) {
if ((LiveDevelopmentUtils.isServerHtmlFileExt(fileInfo.name)) ||
(LiveDevelopmentUtils.isStaticHtmlFileExt(fileInfo.name))) {
return true;
}
} else if (FileUtils.isStaticHtmlFileExt(fileInfo.name)) {
} else if (LiveDevelopmentUtils.isStaticHtmlFileExt(fileInfo.name)) {
return true;
}
} else {
Expand Down Expand Up @@ -629,7 +619,7 @@ define(function (require, exports, module) {

// Optionally prompt for a base URL if no server was found but the
// file is a known server file extension
showBaseUrlPrompt = !_server && FileUtils.isServerHtmlFileExt(doc.file.fullPath);
showBaseUrlPrompt = !_server && LiveDevelopmentUtils.isServerHtmlFileExt(doc.file.fullPath);

if (showBaseUrlPrompt) {
// Prompt for a base URL
Expand Down
23 changes: 10 additions & 13 deletions src/LiveDevelopment/LiveDevelopment.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ define(function LiveDevelopment(require, exports, module) {
var STATUS_SYNC_ERROR = exports.STATUS_SYNC_ERROR = 5;

var Async = require("utils/Async"),
CSSUtils = require("language/CSSUtils"),
Dialogs = require("widgets/Dialogs"),
DefaultDialogs = require("widgets/DefaultDialogs"),
DocumentManager = require("document/DocumentManager"),
Expand All @@ -86,6 +87,7 @@ define(function LiveDevelopment(require, exports, module) {
FileServer = require("LiveDevelopment/Servers/FileServer").FileServer,
FileSystemError = require("filesystem/FileSystemError"),
FileUtils = require("file/FileUtils"),
LiveDevelopmentUtils = require("LiveDevelopment/LiveDevelopmentUtils"),
LiveDevServerManager = require("LiveDevelopment/LiveDevServerManager"),
MainViewManager = require("view/MainViewManager"),
NativeApp = require("utils/NativeApp"),
Expand Down Expand Up @@ -192,11 +194,6 @@ define(function LiveDevelopment(require, exports, module) {
function _isPromisePending(promise) {
return promise && promise.state() === "pending";
}

function _isHtmlFileExt(ext) {
return (FileUtils.isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && FileUtils.isServerHtmlFileExt(ext)));
}

/** Get the current document from the document manager
* _adds extension, url and root to the document
Expand All @@ -219,7 +216,7 @@ define(function LiveDevelopment(require, exports, module) {
return exports.config.experimental ? JSDocument : null;
}

if (_isHtmlFileExt(doc.file.fullPath)) {
if (LiveDevelopmentUtils.isHtmlFileExt(doc.file.fullPath)) {
return HTMLDocument;
}

Expand Down Expand Up @@ -683,7 +680,7 @@ define(function LiveDevelopment(require, exports, module) {
// Is the currently opened document already a file we can use for Live Development?
if (doc) {
refPath = doc.file.fullPath;
if (FileUtils.isStaticHtmlFileExt(refPath) || FileUtils.isServerHtmlFileExt(refPath)) {
if (LiveDevelopmentUtils.isStaticHtmlFileExt(refPath) || LiveDevelopmentUtils.isServerHtmlFileExt(refPath)) {
return new $.Deferred().resolve(doc);
}
}
Expand Down Expand Up @@ -715,11 +712,11 @@ define(function LiveDevelopment(require, exports, module) {
if (fileInfo.fullPath.indexOf(containingFolder) === 0) {
if (FileUtils.getFilenameWithoutExtension(fileInfo.name) === "index") {
if (hasOwnServerForLiveDevelopment) {
if ((FileUtils.isServerHtmlFileExt(fileInfo.name)) ||
(FileUtils.isStaticHtmlFileExt(fileInfo.name))) {
if ((LiveDevelopmentUtils.isServerHtmlFileExt(fileInfo.name)) ||
(LiveDevelopmentUtils.isStaticHtmlFileExt(fileInfo.name))) {
return true;
}
} else if (FileUtils.isStaticHtmlFileExt(fileInfo.name)) {
} else if (LiveDevelopmentUtils.isStaticHtmlFileExt(fileInfo.name)) {
return true;
}
} else {
Expand Down Expand Up @@ -769,15 +766,15 @@ define(function LiveDevelopment(require, exports, module) {
*/
function onActiveEditorChange(event, current, previous) {
if (previous && previous.document &&
FileUtils.isCSSPreprocessorFile(previous.document.file.fullPath)) {
CSSUtils.isCSSPreprocessorFile(previous.document.file.fullPath)) {
var prevDocUrl = _server && _server.pathToUrl(previous.document.file.fullPath);

if (_relatedDocuments && _relatedDocuments[prevDocUrl]) {
_closeRelatedDocument(_relatedDocuments[prevDocUrl]);
}
}
if (current && current.document &&
FileUtils.isCSSPreprocessorFile(current.document.file.fullPath)) {
CSSUtils.isCSSPreprocessorFile(current.document.file.fullPath)) {
var docUrl = _server && _server.pathToUrl(current.document.file.fullPath);
_styleSheetAdded(null, docUrl);
}
Expand Down Expand Up @@ -1258,7 +1255,7 @@ define(function LiveDevelopment(require, exports, module) {
// Optionally prompt for a base URL if no server was found but the
// file is a known server file extension
showBaseUrlPrompt = !exports.config.experimental && !_server &&
FileUtils.isServerHtmlFileExt(doc.file.fullPath);
LiveDevelopmentUtils.isServerHtmlFileExt(doc.file.fullPath);

if (showBaseUrlPrompt) {
// Prompt for a base URL
Expand Down
84 changes: 84 additions & 0 deletions src/LiveDevelopment/LiveDevelopmentUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2015 Adobe Systems Incorporated. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define */

/**
* Set of utilities for working with files and text content.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this module summary is completely wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, good catch -- feel free to put up a small PR with a fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

*/
define(function (require, exports, module) {
"use strict";

var LanguageManager = require("language/LanguageManager"),
ProjectManager = require("project/ProjectManager");

/**
* File extensions - hard-coded for now, but may want to make these preferences
* @const {Array.<string>}
*/
var _staticHtmlFileExts = ["htm", "html", "xhtml"],
_serverHtmlFileExts = ["php", "php3", "php4", "php5", "phtm", "phtml", "cfm", "cfml", "asp", "aspx", "jsp", "jspx", "shtm", "shtml"];

/**
* Determine if file extension is a static html file extension.
* @param {string} filePath could be a path, a file name or just a file extension
* @return {boolean} Returns true if fileExt is in the list
*/
function isStaticHtmlFileExt(filePath) {
if (!filePath) {
return false;
}

return (_staticHtmlFileExts.indexOf(LanguageManager.getLanguageForPath(filePath).getId()) !== -1);
}

/**
* Determine if file extension is a server html file extension.
* @param {string} filePath could be a path, a file name or just a file extension
* @return {boolean} Returns true if fileExt is in the list
*/
function isServerHtmlFileExt(filePath) {
if (!filePath) {
return false;
}

return (_serverHtmlFileExts.indexOf(LanguageManager.getLanguageForPath(filePath).getId()) !== -1);
}

/**
* Returns true if we think the given extension is for an HTML file.
* @param {string} ext The extension to check.
* @return {boolean} true if this is an HTML extension.
*/
function isHtmlFileExt(ext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add docs

return (isStaticHtmlFileExt(ext) ||
(ProjectManager.getBaseUrl() && isServerHtmlFileExt(ext)));
}

// Define public API
exports.isHtmlFileExt = isHtmlFileExt;
exports.isStaticHtmlFileExt = isStaticHtmlFileExt;
exports.isServerHtmlFileExt = isServerHtmlFileExt;
});
8 changes: 4 additions & 4 deletions src/LiveDevelopment/Servers/UserServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
define(function (require, exports, module) {
"use strict";

var BaseServer = require("LiveDevelopment/Servers/BaseServer").BaseServer,
FileUtils = require("file/FileUtils");
var BaseServer = require("LiveDevelopment/Servers/BaseServer").BaseServer,
LiveDevelopmentUtils = require("LiveDevelopment/LiveDevelopmentUtils");

/**
* Live preview server for user specified server as defined with Live Preview Base Url
Expand Down Expand Up @@ -68,8 +68,8 @@ define(function (require, exports, module) {
return false;
}

return FileUtils.isStaticHtmlFileExt(localPath) ||
FileUtils.isServerHtmlFileExt(localPath);
return LiveDevelopmentUtils.isStaticHtmlFileExt(localPath) ||
LiveDevelopmentUtils.isServerHtmlFileExt(localPath);
};

exports.UserServer = UserServer;
Expand Down
24 changes: 22 additions & 2 deletions src/document/DocumentCommandHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,23 @@ define(function (require, exports, module) {
_updateTitle();
}
}

/**
* Shows an error dialog indicating that the given file could not be opened due to the given error
* @param {!FileSystemError} name
* @return {!Dialog}
*/
function showFileOpenError(name, path) {
return Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_ERROR,
Strings.ERROR_OPENING_FILE_TITLE,
StringUtils.format(
Strings.ERROR_OPENING_FILE,
StringUtils.breakableUrl(path),
FileUtils.getFileErrorString(name)
)
);
}

/**
* @private
Expand Down Expand Up @@ -288,7 +305,7 @@ define(function (require, exports, module) {
if (silent) {
_cleanup(fileError, fullFilePath);
} else {
FileUtils.showFileOpenError(fileError, fullFilePath).done(function () {
showFileOpenError(fileError, fullFilePath).done(function () {
_cleanup(fileError, fullFilePath);
});
}
Expand Down Expand Up @@ -803,7 +820,7 @@ define(function (require, exports, module) {
if (suppressError) {
result.resolve();
} else {
FileUtils.showFileOpenError(error, doc.file.fullPath)
showFileOpenError(error, doc.file.fullPath)
.done(function () {
result.reject(error);
});
Expand Down Expand Up @@ -1675,6 +1692,9 @@ define(function (require, exports, module) {
} else if (brackets.platform === "mac") {
showInOS = Strings.CMD_SHOW_IN_FINDER;
}

// Define public API
exports.showFileOpenError = showFileOpenError;

// Deprecated commands
CommandManager.register(Strings.CMD_ADD_TO_WORKING_SET, Commands.FILE_ADD_TO_WORKING_SET, handleFileAddToWorkingSet);
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/default/StaticServer/StaticServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define(function (require, exports, module) {
"use strict";

var BaseServer = brackets.getModule("LiveDevelopment/Servers/BaseServer").BaseServer,
FileUtils = brackets.getModule("file/FileUtils"),
LiveDevelopmentUtils = brackets.getModule("LiveDevelopment/LiveDevelopmentUtils"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager");


Expand Down Expand Up @@ -87,7 +87,7 @@ define(function (require, exports, module) {
}

// FUTURE: do a MIME Type lookup on file extension
return FileUtils.isStaticHtmlFileExt(localPath);
return LiveDevelopmentUtils.isStaticHtmlFileExt(localPath);
};

/**
Expand Down
Loading