Skip to content

Commit 866a4e7

Browse files
committed
refactor: using event ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH
1 parent 42153fd commit 866a4e7

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

src/extensions/default/JSLint/ESLint.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ define(function (require, exports, module) {
3737
Strings = brackets.getModule("strings"),
3838
StringUtils = brackets.getModule("utils/StringUtils"),
3939
ProjectManager = brackets.getModule("project/ProjectManager"),
40-
FileSystem = brackets.getModule("filesystem/FileSystem"),
4140
LanguageManager = brackets.getModule("language/LanguageManager"),
4241
NodeUtils = brackets.getModule("utils/NodeUtils"),
4342
Metrics = brackets.getModule("utils/Metrics");
@@ -242,28 +241,15 @@ define(function (require, exports, module) {
242241
});
243242
}
244243

245-
function _isFileInArray(fileToCheck, fileArray){
246-
if(!fileArray){
247-
return false;
248-
}
249-
for(let file of fileArray){
250-
if(file.fullPath === fileToCheck.fullPath){
251-
return true;
252-
}
253-
}
254-
return false;
255-
}
256-
257-
function _projectFileChanged(_evt, entry, added, removed) {
258-
let configFilePath = FileSystem.getFileForPath(ProjectManager.getProjectRoot().fullPath + PACKAGE_JSON);
259-
if(entry && entry.fullPath === configFilePath.fullPath
260-
|| _isFileInArray(configFilePath, added) || _isFileInArray(configFilePath, removed)){
244+
function _projectFileChanged(_evt, changedPath, addedSet, removedSet) {
245+
let configPath = path.join(ProjectManager.getProjectRoot().fullPath, PACKAGE_JSON);
246+
if(changedPath=== configPath || addedSet.has(configPath) || removedSet.has(configPath)){
261247
_reloadOptions();
262248
}
263249
}
264250

265251
AppInit.appReady(function () {
266-
ProjectManager.on(ProjectManager.EVENT_PROJECT_FILE_CHANGED, _projectFileChanged);
252+
ProjectManager.on(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _projectFileChanged);
267253
ProjectManager.on(ProjectManager.EVENT_PROJECT_OPEN, function () {
268254
_reloadOptions();
269255
if(!Phoenix.isNativeApp) {

src/extensions/default/JSLint/JSHint.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,31 +244,18 @@ define(function (require, exports, module) {
244244
return !!(jsHintConfigFileErrorMessage || projectSpecificOptions);
245245
}
246246

247-
function _isFileInArray(fileToCheck, fileArray){
248-
if(!fileArray){
249-
return false;
250-
}
251-
for(let file of fileArray){
252-
if(file.fullPath === fileToCheck.fullPath){
253-
return true;
254-
}
255-
}
256-
return false;
257-
}
258-
259-
function _projectFileChanged(_evt, entry, added, removed) {
260-
let configFilePath = FileSystem.getFileForPath(ProjectManager.getProjectRoot().fullPath + CONFIG_FILE_NAME);
261-
if(entry && entry.fullPath === configFilePath.fullPath
262-
|| _isFileInArray(configFilePath, added)){
247+
function _projectFileChanged(_evt, changedPath, addedSet, removedSet) {
248+
let configPath = path.join(ProjectManager.getProjectRoot().fullPath, CONFIG_FILE_NAME);
249+
if(changedPath === configPath || addedSet.has(configPath)){
263250
_reloadOptions();
264-
} else if(_isFileInArray(configFilePath, removed)){
251+
} else if(removedSet.has(configPath)){
265252
projectSpecificOptions = null;
266253
jsHintConfigFileErrorMessage = null;
267254
}
268255
}
269256

270257
AppInit.appReady(function () {
271-
ProjectManager.on(ProjectManager.EVENT_PROJECT_FILE_CHANGED, _projectFileChanged);
258+
ProjectManager.on(ProjectManager.EVENT_PROJECT_CHANGED_OR_RENAMED_PATH, _projectFileChanged);
272259
ProjectManager.on(ProjectManager.EVENT_PROJECT_OPEN, _reloadOptions);
273260
_reloadOptions();
274261
});

src/extensionsIntegrated/Phoenix-live-preview/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ define(function (require, exports, module) {
541541
}
542542

543543
async function _projectFileChanges(evt, changedFile) {
544-
if(changedFile && (utils.isPreviewableFile(changedFile.fullPath) ||
544+
if(changedFile && changedFile.isFile && (utils.isPreviewableFile(changedFile.fullPath) ||
545545
utils.isServerRenderedFile(changedFile.fullPath))){
546546
// we are getting this change event somehow.
547547
// bug, investigate why we get this change event as a project file change.

src/nls/root/strings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ define({
11741174
"BEAUTIFY_CODE_NOTIFICATION": "Click here or press <b>`{0}`</b> to Beautify code. </br> <img src=\"styles/images/beautify.gif\"> <br/> <a href='#' style='float:right;'>ok</a>",
11751175
"DEFAULT_PROJECT_NOTIFICATION": "Click here to open the <br/><b>default project</b> in phoenix. </br> <a href='#' style='float:right;'>ok</a>",
11761176
"DIRECTORY_REPLACE_MESSAGE": "The selected folder <span class='dialog-filename'>{0}</span> is not empty. Are you sure you want to replace the folder contents with the project?",
1177-
"DEFAULT_PROJECT_HTML_CLICK_HERE": "Click here to locate this &ltspan&gt in the HTML file",
1177+
"DEFAULT_PROJECT_HTML_CLICK_HERE": "Click here to locate this &lt;span&gt; in the HTML file",
11781178
"BUILD_WEBSITE_SECTION": "Build Website",
11791179
"LEARN_SECTION": "Learn With Examples",
11801180
"CREATE_EXTENSION_SECTION": "Create {APP_NAME} Extensions and Themes",

0 commit comments

Comments
 (0)