From 3cbacd8b51f1417c263640a553d3f3da2d35f77a Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Tue, 10 Mar 2020 11:53:57 +0530 Subject: [PATCH 1/9] detect graphics file in a project --- .../GraphicsFile.js | 83 +++++++++++++++++++ .../OpenWithExternalApplication/main.js | 8 +- .../node/OpenWithExternalApplicationDomain.js | 64 +++++++++++++- .../node/package.json | 3 +- 4 files changed, 155 insertions(+), 3 deletions(-) create mode 100644 src/extensions/default/OpenWithExternalApplication/GraphicsFile.js diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js new file mode 100644 index 00000000000..e46f13e0df7 --- /dev/null +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2013 - present 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. + * + */ + +define(function (require, exports, module) { + "use strict"; + + + var PreferencesManager = brackets.getModule("preferences/PreferencesManager"), + Strings = brackets.getModule("strings"), + ProjectManager = brackets.getModule("project/ProjectManager"); + + + var _requestID = 0, + _initialized = false; + + var _graphicsFileTypes = ["jpg", "jpeg", "png", "svg", "xd", "psd", "ai"]; + + var _nodeDomain; + + function init(nodeDomain) { + + if(_initialized) { + return; + } + _initialized = true; + + _nodeDomain = nodeDomain; + + _nodeDomain.on('checkFileTypesInFolderResponse', function (event, response) { + if(response.id !== _requestID) { + return; + } + _graphicsFilePresentInProject(response.present) + }); + + ProjectManager.on("projectOpen", function () { + _checkForGraphicsFileInPrjct(); + }); + + _checkForGraphicsFileInPrjct(); + + } + + + function _checkForGraphicsFileInPrjct() { + + _nodeDomain.exec("checkFileTypesInFolder", { + extensions: _graphicsFileTypes.join(), + folder: ProjectManager.getProjectRoot().fullPath, + reqId: ++_requestID + }); + + } + + function _graphicsFilePresentInProject(isPresent) { + + console.log("Graphics File present in project", isPresent); + + } + + exports.init = init; + +}); diff --git a/src/extensions/default/OpenWithExternalApplication/main.js b/src/extensions/default/OpenWithExternalApplication/main.js index 535a6333ee7..419946c7164 100644 --- a/src/extensions/default/OpenWithExternalApplication/main.js +++ b/src/extensions/default/OpenWithExternalApplication/main.js @@ -29,9 +29,11 @@ define(function (require, exports, module) { PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), FileViewController = brackets.getModule("project/FileViewController"), + ProjectManager = brackets.getModule("project/ProjectManager"), ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), NodeDomain = brackets.getModule("utils/NodeDomain"), - FileUtils = brackets.getModule("file/FileUtils"); + FileUtils = brackets.getModule("file/FileUtils"), + GraphicsFile = require("GraphicsFile"); /** * @private @@ -47,6 +49,8 @@ define(function (require, exports, module) { var extensionToExtApplicationMap = {}; + var graphicsFileTypes = [".jpg", ".jpeg", ".png", ".svg", ".xd", ".psd", ".ai"]; + function _openWithExternalApplication(event, path) { _nodeDomain.exec("open", { path: path, @@ -66,6 +70,8 @@ define(function (require, exports, module) { FileViewController.on("openWithExternalApplication", _openWithExternalApplication); AppInit.appReady(function () { + + GraphicsFile.init(_nodeDomain); extensionToExtApplicationMap = PreferencesManager.get("externalApplications"); FileUtils.addExtensionToExternalAppList(Object.keys(extensionToExtApplicationMap)); }); diff --git a/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js b/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js index 8a864689ef6..b0987614bb0 100644 --- a/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js +++ b/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js @@ -25,7 +25,9 @@ /*jslint node: true */ "use strict"; -var open = require("open"); +var open = require("open"), + Glob = require("glob").Glob, + path = require('path'); var _domainManager; @@ -39,6 +41,39 @@ function _openWithExternalApplication(params) { open(params.path, application); } +/** + * @private + * + * @param {Object} params Object to use + */ +function _checkFileTypesInFolder(params) { + + var extList = params.extensions, + dirPath = path.normalize(params.folder), + + pattern = dirPath + "/**/*.+(" + extList.replace(",", "|") + ")"; + //pattern = dirPath + "/**/*.jpg"; + + var mg = new Glob(pattern, function (err, matches) { + + var respObj = { + id: params.reqId, + present: matches.length > 0 ? true : false + } + _domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); + }); + + mg.on("match", function() { + //mg.abort(); + var respObj = { + id: params.reqId, + present: true + } + //_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); + }); + +} + /** * Initializes the OpenWithExternalEditor domain with its commands. @@ -50,6 +85,7 @@ function init(domainManager) { if (!domainManager.hasDomain("OpenWithExternalApplication")) { domainManager.registerDomain("OpenWithExternalApplication", {major: 0, minor: 1}); } + _domainManager.registerCommand( "OpenWithExternalApplication", "open", @@ -63,6 +99,32 @@ function init(domainManager) { }], [] ); + + _domainManager.registerCommand( + "OpenWithExternalApplication", + "checkFileTypesInFolder", + _checkFileTypesInFolder, + true, + "looks for File Types in a folder.", + [{ + name: "params", + type: "object", + description: "Params Object having File Extensions and Folder Path." + }], + [] + ); + + _domainManager.registerEvent( + "OpenWithExternalApplication", + "checkFileTypesInFolderResponse", + [ + { + name: "msgObj", + type: "object", + description: "json object containing message info to pass to brackets" + } + ] + ); } exports.init = init; diff --git a/src/extensions/default/OpenWithExternalApplication/node/package.json b/src/extensions/default/OpenWithExternalApplication/node/package.json index 65bb049736e..0e646495964 100644 --- a/src/extensions/default/OpenWithExternalApplication/node/package.json +++ b/src/extensions/default/OpenWithExternalApplication/node/package.json @@ -1,6 +1,7 @@ { "name": "brackets-open-external_application", "dependencies": { - "open": "0.0.5" + "open": "0.0.5", + "glob": "7.1.1" } } From e8a829cbcf95853f57a09657f69f2f3c607310ac Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Thu, 12 Mar 2020 20:34:43 +0530 Subject: [PATCH 2/9] changes to detect graphics file in a project --- .../GraphicsFile.js | 54 ++++++++++++++++++- .../node/OpenWithExternalApplicationDomain.js | 11 ++-- src/nls/root/strings.js | 7 ++- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js index e46f13e0df7..55f79d83d00 100644 --- a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -27,13 +27,16 @@ define(function (require, exports, module) { var PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), - ProjectManager = brackets.getModule("project/ProjectManager"); + ProjectManager = brackets.getModule("project/ProjectManager"), + Dialogs = brackets.getModule("widgets/Dialogs"), + DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"); var _requestID = 0, _initialized = false; var _graphicsFileTypes = ["jpg", "jpeg", "png", "svg", "xd", "psd", "ai"]; + //var _graphicsFileTypes = [ "psd"]; var _nodeDomain; @@ -64,6 +67,10 @@ define(function (require, exports, module) { function _checkForGraphicsFileInPrjct() { + if(PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) { + return; + } + _nodeDomain.exec("checkFileTypesInFolder", { extensions: _graphicsFileTypes.join(), folder: ProjectManager.getProjectRoot().fullPath, @@ -74,7 +81,50 @@ define(function (require, exports, module) { function _graphicsFilePresentInProject(isPresent) { - console.log("Graphics File present in project", isPresent); + if(!isPresent) { + return; + } + + Dialogs.showModalDialog( + DefaultDialogs.DIALOG_ID_INFO, + Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE, + Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG, + [ + { className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL, + text: Strings.BUTTON_NO + }, + { className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK, + text: Strings.BUTTON_YES + } + ] + ).done(function (id) { + + if(id !== Dialogs.DIALOG_BTN_OK) + return; + + brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) { + var associateApp = out.split(','), + fileTypeToAppMap = {}; + + associateApp.forEach(function(item) { + fileTypeToAppMap[item.split(':')[0]] = item.split(':')[1] + }); + Dialogs.showModalDialog( + DefaultDialogs.DIALOG_ID_INFO, + Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE, + out, + [ + { className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL, + text: Strings.BUTTON_NO + }, + { className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK, + text: Strings.BUTTON_YES + } + ] + ) + }); + }); + PreferencesManager.setViewState("AssociateGraphicsFileDialogShown", true); } diff --git a/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js b/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js index b0987614bb0..996a99bdef1 100644 --- a/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js +++ b/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js @@ -51,10 +51,9 @@ function _checkFileTypesInFolder(params) { var extList = params.extensions, dirPath = path.normalize(params.folder), - pattern = dirPath + "/**/*.+(" + extList.replace(",", "|") + ")"; - //pattern = dirPath + "/**/*.jpg"; + pattern = dirPath + "/**/*.+(" + extList.replace(/,/g, "|") + ")"; - var mg = new Glob(pattern, function (err, matches) { + var globMgr = new Glob(pattern, function (err, matches) { var respObj = { id: params.reqId, @@ -63,13 +62,13 @@ function _checkFileTypesInFolder(params) { _domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); }); - mg.on("match", function() { - //mg.abort(); + globMgr.on("match", function() { + globMgr.abort(); var respObj = { id: params.reqId, present: true } - //_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); + _domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); }); } diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index e01b2300aeb..69f8803d620 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -906,5 +906,10 @@ define({ "REMOTE_DEBUGGING_PORT_INVALID" : "Cannot enable remote debugging on port {0}. Port numbers should be between {1} and {2}.", //Associate File Type to External App - "DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Add File type association to external App here" + "DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Add File type association to external App here", + + "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphics Files in external editors?", + "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Click Yes to associate the graphic files with its appropriate external editors." + + }); From 52e9414d35aeee6797898c89f8d85e8e04fe5952 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Thu, 12 Mar 2020 20:40:04 +0530 Subject: [PATCH 3/9] corrected eslint error --- .../default/OpenWithExternalApplication/GraphicsFile.js | 9 +++++---- .../node/OpenWithExternalApplicationDomain.js | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js index 55f79d83d00..81c88ab5fbd 100644 --- a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -53,7 +53,7 @@ define(function (require, exports, module) { if(response.id !== _requestID) { return; } - _graphicsFilePresentInProject(response.present) + _graphicsFilePresentInProject(response.present); }); ProjectManager.on("projectOpen", function () { @@ -99,15 +99,16 @@ define(function (require, exports, module) { ] ).done(function (id) { - if(id !== Dialogs.DIALOG_BTN_OK) + if(id !== Dialogs.DIALOG_BTN_OK) { return; + } brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) { var associateApp = out.split(','), fileTypeToAppMap = {}; associateApp.forEach(function(item) { - fileTypeToAppMap[item.split(':')[0]] = item.split(':')[1] + fileTypeToAppMap[item.split(':')[0]] = item.split(':')[1]; }); Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_INFO, @@ -121,7 +122,7 @@ define(function (require, exports, module) { text: Strings.BUTTON_YES } ] - ) + ); }); }); PreferencesManager.setViewState("AssociateGraphicsFileDialogShown", true); diff --git a/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js b/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js index 996a99bdef1..e5a7e414585 100644 --- a/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js +++ b/src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js @@ -58,7 +58,7 @@ function _checkFileTypesInFolder(params) { var respObj = { id: params.reqId, present: matches.length > 0 ? true : false - } + }; _domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); }); @@ -67,7 +67,7 @@ function _checkFileTypesInFolder(params) { var respObj = { id: params.reqId, present: true - } + }; _domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]); }); From 2dea43e2cb4a45054601fe4a9c3e25d55185da51 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 13 Mar 2020 00:57:38 +0530 Subject: [PATCH 4/9] updating preferences file with default app --- .../GraphicsFile.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js index 81c88ab5fbd..b295c0c8e01 100644 --- a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -36,7 +36,6 @@ define(function (require, exports, module) { _initialized = false; var _graphicsFileTypes = ["jpg", "jpeg", "png", "svg", "xd", "psd", "ai"]; - //var _graphicsFileTypes = [ "psd"]; var _nodeDomain; @@ -104,12 +103,29 @@ define(function (require, exports, module) { } brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) { + + if(err) { + return; + } var associateApp = out.split(','), fileTypeToAppMap = {}; associateApp.forEach(function(item) { - fileTypeToAppMap[item.split(':')[0]] = item.split(':')[1]; + fileTypeToAppMap[item.split('##')[0]] = item.split('##')[1]; }); + + var prefs = PreferencesManager.get('externalApplications'); + + for (var key in fileTypeToAppMap) { + if (fileTypeToAppMap.hasOwnProperty(key)) { + if(key && !prefs[key]) { + prefs[key] = "default"; + } + } + } + + PreferencesManager.set('externalApplications', prefs); + Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_INFO, Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE, From 7154baf13a1fd78b1f535781719aaaafc472434f Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 13 Mar 2020 01:05:51 +0530 Subject: [PATCH 5/9] code clean up --- src/extensions/default/OpenWithExternalApplication/main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/extensions/default/OpenWithExternalApplication/main.js b/src/extensions/default/OpenWithExternalApplication/main.js index 419946c7164..a8e7ad69995 100644 --- a/src/extensions/default/OpenWithExternalApplication/main.js +++ b/src/extensions/default/OpenWithExternalApplication/main.js @@ -49,8 +49,6 @@ define(function (require, exports, module) { var extensionToExtApplicationMap = {}; - var graphicsFileTypes = [".jpg", ".jpeg", ".png", ".svg", ".xd", ".psd", ".ai"]; - function _openWithExternalApplication(event, path) { _nodeDomain.exec("open", { path: path, From 6f33003624e9e4d3fef98d4ee2d74af35b224fcf Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 13 Mar 2020 01:13:44 +0530 Subject: [PATCH 6/9] code clean up --- src/extensions/default/OpenWithExternalApplication/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extensions/default/OpenWithExternalApplication/main.js b/src/extensions/default/OpenWithExternalApplication/main.js index a8e7ad69995..5587da39775 100644 --- a/src/extensions/default/OpenWithExternalApplication/main.js +++ b/src/extensions/default/OpenWithExternalApplication/main.js @@ -29,7 +29,6 @@ define(function (require, exports, module) { PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), FileViewController = brackets.getModule("project/FileViewController"), - ProjectManager = brackets.getModule("project/ProjectManager"), ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), NodeDomain = brackets.getModule("utils/NodeDomain"), FileUtils = brackets.getModule("file/FileUtils"), From 9c722a6be5a166d24b167364172440190baab09e Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Fri, 13 Mar 2020 12:42:55 +0530 Subject: [PATCH 7/9] Application Name correction --- .../default/OpenWithExternalApplication/GraphicsFile.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js index b295c0c8e01..ce30d3650b7 100644 --- a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -119,7 +119,11 @@ define(function (require, exports, module) { for (var key in fileTypeToAppMap) { if (fileTypeToAppMap.hasOwnProperty(key)) { if(key && !prefs[key]) { - prefs[key] = "default"; + prefs[key] = fileTypeToAppMap[key]; + if(brackets.platform === "win" && !fileTypeToAppMap[key].endsWith('.exe') && + !fileTypeToAppMap[key].endsWith('.EXE')) { + prefs[key] = "default"; + } } } } From 4d7268dc9a5d6e5cdc2754d42c647f5a4eed3122 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Tue, 17 Mar 2020 23:56:17 +0530 Subject: [PATCH 8/9] added analytics data loggiing --- .../GraphicsFile.js | 94 +++++++++++++++---- src/nls/root/strings.js | 7 +- 2 files changed, 78 insertions(+), 23 deletions(-) diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js index ce30d3650b7..894ed7e0b65 100644 --- a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -27,9 +27,11 @@ define(function (require, exports, module) { var PreferencesManager = brackets.getModule("preferences/PreferencesManager"), Strings = brackets.getModule("strings"), + StringsUtils = brackets.getModule("utils/StringUtils"), ProjectManager = brackets.getModule("project/ProjectManager"), Dialogs = brackets.getModule("widgets/Dialogs"), - DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"); + DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"), + HealthLogger = brackets.getModule("utils/HealthLogger"); var _requestID = 0, @@ -41,7 +43,7 @@ define(function (require, exports, module) { function init(nodeDomain) { - if(_initialized) { + if (_initialized) { return; } _initialized = true; @@ -49,7 +51,7 @@ define(function (require, exports, module) { _nodeDomain = nodeDomain; _nodeDomain.on('checkFileTypesInFolderResponse', function (event, response) { - if(response.id !== _requestID) { + if (response.id !== _requestID) { return; } _graphicsFilePresentInProject(response.present); @@ -66,7 +68,7 @@ define(function (require, exports, module) { function _checkForGraphicsFileInPrjct() { - if(PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) { + if (PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) { return; } @@ -80,7 +82,7 @@ define(function (require, exports, module) { function _graphicsFilePresentInProject(isPresent) { - if(!isPresent) { + if (!isPresent) { return; } @@ -90,28 +92,66 @@ define(function (require, exports, module) { Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG, [ { className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL, - text: Strings.BUTTON_NO + text: Strings.CANCEL }, { className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK, - text: Strings.BUTTON_YES + text: Strings.OK } ] ).done(function (id) { - - if(id !== Dialogs.DIALOG_BTN_OK) { + + if (id !== Dialogs.DIALOG_BTN_OK) { + HealthLogger.sendAnalyticsData( + "externalEditorsCancelled", + "usage", + "externalEditors", + "Cancelled", + "" + ); return; } + HealthLogger.sendAnalyticsData( + "LinkExternalEditors", + "usage", + "externalEditors", + "LinkExternalEditors", + "" + ); brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) { - if(err) { + if (err) { return; } var associateApp = out.split(','), - fileTypeToAppMap = {}; + fileTypeToAppMap = {}, + AppToFileTypeMap = {}; + + associateApp.forEach(function (item) { + + var filetype = item.split('##')[0], + app = item.split('##')[1]; + + if (!filetype) { + return; + } + + if (filetype === "xd") { + if (app.toLowerCase() !== "adobe xd" && app !== "adobe.cc.xd") { + return; + } + app = "Adobe XD"; + } + fileTypeToAppMap[filetype] = app; - associateApp.forEach(function(item) { - fileTypeToAppMap[item.split('##')[0]] = item.split('##')[1]; + if (brackets.platform === "win" && !app.toLowerCase().endsWith('.exe')) { + app = app.substring(app.lastIndexOf('//') + 2, app.length - 4); + } + if (AppToFileTypeMap[app]) { + AppToFileTypeMap[app].push(filetype); + } else { + AppToFileTypeMap[app] = [filetype]; + } }); var prefs = PreferencesManager.get('externalApplications'); @@ -120,26 +160,40 @@ define(function (require, exports, module) { if (fileTypeToAppMap.hasOwnProperty(key)) { if(key && !prefs[key]) { prefs[key] = fileTypeToAppMap[key]; - if(brackets.platform === "win" && !fileTypeToAppMap[key].endsWith('.exe') && - !fileTypeToAppMap[key].endsWith('.EXE')) { + if(brackets.platform === "win" && !fileTypeToAppMap[key].toLowerCase().endsWith('.exe')) { prefs[key] = "default"; } + HealthLogger.sendAnalyticsData( + "AddExternalEditorForFileType_" + key.toUpperCase(), + "usage", + "externalEditors", + "AddExternalEditorForFileType_" + key.toUpperCase(), + "" + ); } } } PreferencesManager.set('externalApplications', prefs); + var str = ""; + for(var app in AppToFileTypeMap) { + str += AppToFileTypeMap[app].join() + "->" + app + "
"; + } + + if(!str) { + return; + } + + str+="
"; + Dialogs.showModalDialog( DefaultDialogs.DIALOG_ID_INFO, Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE, - out, + StringsUtils.format(Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG, str), [ - { className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL, - text: Strings.BUTTON_NO - }, { className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK, - text: Strings.BUTTON_YES + text: Strings.OK } ] ); diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 69f8803d620..5dbd01360ec 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -906,10 +906,11 @@ define({ "REMOTE_DEBUGGING_PORT_INVALID" : "Cannot enable remote debugging on port {0}. Port numbers should be between {1} and {2}.", //Associate File Type to External App - "DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Add File type association to external App here", + "DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Associate File type to external App settings. e.g { \"\": \"\" } app_name is OS dependant, for example \"google chrome\" on macOS and \"chrome\" on Windows. app_name can also be given as \"default\" for OS default application.", - "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphics Files in external editors?", - "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Click Yes to associate the graphic files with its appropriate external editors." + "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphic Files in External Editors.", + "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Your current folder has graphic file types which are not supported by Brackets.
You can now associate specific file types with external editors. Once associated, you can open graphic files like .xd, .psd, .jpg, .png, .ai, .svg in their default applications by double clicking on the files in File Tree.

Please click on ‘Ok’ button to associate the graphic file types with their respective default applications.", + "ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG" : "Following file types have been successfully associated with default applications.
{0} You can further add new file type associations or customize in brackets.json by going to “Debug->Open Preferences File” menu." }); From 5fb5763e6369d90a3974018810f16a38b2eafd33 Mon Sep 17 00:00:00 2001 From: Nitesh Kumar Date: Wed, 18 Mar 2020 00:25:48 +0530 Subject: [PATCH 9/9] code corrections --- .../default/OpenWithExternalApplication/GraphicsFile.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js index 894ed7e0b65..d8ac00ce077 100644 --- a/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js +++ b/src/extensions/default/OpenWithExternalApplication/GraphicsFile.js @@ -137,15 +137,16 @@ define(function (require, exports, module) { } if (filetype === "xd") { - if (app.toLowerCase() !== "adobe xd" && app !== "adobe.cc.xd") { + if (app.toLowerCase() !== "adobe xd" && app.toLowerCase() !== "adobe.cc.xd") { return; } + app = "Adobe XD"; } fileTypeToAppMap[filetype] = app; - if (brackets.platform === "win" && !app.toLowerCase().endsWith('.exe')) { - app = app.substring(app.lastIndexOf('//') + 2, app.length - 4); + if (brackets.platform === "win" && app.toLowerCase().endsWith('.exe')) { + app = app.substring(app.lastIndexOf('\\') + 1, app.length - 4); } if (AppToFileTypeMap[app]) { AppToFileTypeMap[app].push(filetype);