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

Commit 7a8ce6a

Browse files
committed
Merge branch 'master' into alf_localization_1.14
2 parents 3f1cfeb + 62c23d3 commit 7a8ce6a

File tree

5 files changed

+284
-4
lines changed

5 files changed

+284
-4
lines changed
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* Copyright (c) 2013 - present Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
define(function (require, exports, module) {
25+
"use strict";
26+
27+
28+
var PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
29+
Strings = brackets.getModule("strings"),
30+
StringsUtils = brackets.getModule("utils/StringUtils"),
31+
ProjectManager = brackets.getModule("project/ProjectManager"),
32+
Dialogs = brackets.getModule("widgets/Dialogs"),
33+
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
34+
HealthLogger = brackets.getModule("utils/HealthLogger");
35+
36+
37+
var _requestID = 0,
38+
_initialized = false;
39+
40+
var _graphicsFileTypes = ["jpg", "jpeg", "png", "svg", "xd", "psd", "ai"];
41+
42+
var _nodeDomain;
43+
44+
function init(nodeDomain) {
45+
46+
if (_initialized) {
47+
return;
48+
}
49+
_initialized = true;
50+
51+
_nodeDomain = nodeDomain;
52+
53+
_nodeDomain.on('checkFileTypesInFolderResponse', function (event, response) {
54+
if (response.id !== _requestID) {
55+
return;
56+
}
57+
_graphicsFilePresentInProject(response.present);
58+
});
59+
60+
ProjectManager.on("projectOpen", function () {
61+
_checkForGraphicsFileInPrjct();
62+
});
63+
64+
_checkForGraphicsFileInPrjct();
65+
66+
}
67+
68+
69+
function _checkForGraphicsFileInPrjct() {
70+
71+
if (PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) {
72+
return;
73+
}
74+
75+
_nodeDomain.exec("checkFileTypesInFolder", {
76+
extensions: _graphicsFileTypes.join(),
77+
folder: ProjectManager.getProjectRoot().fullPath,
78+
reqId: ++_requestID
79+
});
80+
81+
}
82+
83+
function _graphicsFilePresentInProject(isPresent) {
84+
85+
if (!isPresent) {
86+
return;
87+
}
88+
89+
Dialogs.showModalDialog(
90+
DefaultDialogs.DIALOG_ID_INFO,
91+
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE,
92+
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG,
93+
[
94+
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
95+
text: Strings.CANCEL
96+
},
97+
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
98+
text: Strings.OK
99+
}
100+
]
101+
).done(function (id) {
102+
103+
if (id !== Dialogs.DIALOG_BTN_OK) {
104+
HealthLogger.sendAnalyticsData(
105+
"externalEditorsCancelled",
106+
"usage",
107+
"externalEditors",
108+
"Cancelled",
109+
""
110+
);
111+
return;
112+
}
113+
HealthLogger.sendAnalyticsData(
114+
"LinkExternalEditors",
115+
"usage",
116+
"externalEditors",
117+
"LinkExternalEditors",
118+
""
119+
);
120+
121+
brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) {
122+
123+
if (err) {
124+
return;
125+
}
126+
var associateApp = out.split(','),
127+
fileTypeToAppMap = {},
128+
AppToFileTypeMap = {};
129+
130+
associateApp.forEach(function (item) {
131+
132+
var filetype = item.split('##')[0],
133+
app = item.split('##')[1];
134+
135+
if (!filetype) {
136+
return;
137+
}
138+
139+
if (filetype === "xd") {
140+
if (app.toLowerCase() !== "adobe xd" && app.toLowerCase() !== "adobe.cc.xd") {
141+
return;
142+
}
143+
144+
app = "Adobe XD";
145+
}
146+
fileTypeToAppMap[filetype] = app;
147+
148+
if (brackets.platform === "win" && app.toLowerCase().endsWith('.exe')) {
149+
app = app.substring(app.lastIndexOf('\\') + 1, app.length - 4);
150+
}
151+
if (AppToFileTypeMap[app]) {
152+
AppToFileTypeMap[app].push(filetype);
153+
} else {
154+
AppToFileTypeMap[app] = [filetype];
155+
}
156+
});
157+
158+
var prefs = PreferencesManager.get('externalApplications');
159+
160+
for (var key in fileTypeToAppMap) {
161+
if (fileTypeToAppMap.hasOwnProperty(key)) {
162+
if(key && !prefs[key]) {
163+
prefs[key] = fileTypeToAppMap[key];
164+
if(brackets.platform === "win" && !fileTypeToAppMap[key].toLowerCase().endsWith('.exe')) {
165+
prefs[key] = "default";
166+
}
167+
HealthLogger.sendAnalyticsData(
168+
"AddExternalEditorForFileType_" + key.toUpperCase(),
169+
"usage",
170+
"externalEditors",
171+
"AddExternalEditorForFileType_" + key.toUpperCase(),
172+
""
173+
);
174+
}
175+
}
176+
}
177+
178+
PreferencesManager.set('externalApplications', prefs);
179+
180+
var str = "";
181+
for(var app in AppToFileTypeMap) {
182+
str += AppToFileTypeMap[app].join() + "->" + app + "<br/>";
183+
}
184+
185+
if(!str) {
186+
return;
187+
}
188+
189+
str+="<br/>";
190+
191+
Dialogs.showModalDialog(
192+
DefaultDialogs.DIALOG_ID_INFO,
193+
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE,
194+
StringsUtils.format(Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG, str),
195+
[
196+
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
197+
text: Strings.OK
198+
}
199+
]
200+
);
201+
});
202+
});
203+
PreferencesManager.setViewState("AssociateGraphicsFileDialogShown", true);
204+
205+
}
206+
207+
exports.init = init;
208+
209+
});

src/extensions/default/OpenWithExternalApplication/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ define(function (require, exports, module) {
3131
FileViewController = brackets.getModule("project/FileViewController"),
3232
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
3333
NodeDomain = brackets.getModule("utils/NodeDomain"),
34-
FileUtils = brackets.getModule("file/FileUtils");
34+
FileUtils = brackets.getModule("file/FileUtils"),
35+
GraphicsFile = require("GraphicsFile");
3536

3637
/**
3738
* @private
@@ -66,6 +67,8 @@ define(function (require, exports, module) {
6667
FileViewController.on("openWithExternalApplication", _openWithExternalApplication);
6768

6869
AppInit.appReady(function () {
70+
71+
GraphicsFile.init(_nodeDomain);
6972
extensionToExtApplicationMap = PreferencesManager.get("externalApplications");
7073
FileUtils.addExtensionToExternalAppList(Object.keys(extensionToExtApplicationMap));
7174
});

src/extensions/default/OpenWithExternalApplication/node/OpenWithExternalApplicationDomain.js

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
/*jslint node: true */
2626
"use strict";
2727

28-
var open = require("open");
28+
var open = require("open"),
29+
Glob = require("glob").Glob,
30+
path = require('path');
2931

3032
var _domainManager;
3133

@@ -39,6 +41,38 @@ function _openWithExternalApplication(params) {
3941
open(params.path, application);
4042
}
4143

44+
/**
45+
* @private
46+
*
47+
* @param {Object} params Object to use
48+
*/
49+
function _checkFileTypesInFolder(params) {
50+
51+
var extList = params.extensions,
52+
dirPath = path.normalize(params.folder),
53+
54+
pattern = dirPath + "/**/*.+(" + extList.replace(/,/g, "|") + ")";
55+
56+
var globMgr = new Glob(pattern, function (err, matches) {
57+
58+
var respObj = {
59+
id: params.reqId,
60+
present: matches.length > 0 ? true : false
61+
};
62+
_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
63+
});
64+
65+
globMgr.on("match", function() {
66+
globMgr.abort();
67+
var respObj = {
68+
id: params.reqId,
69+
present: true
70+
};
71+
_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
72+
});
73+
74+
}
75+
4276

4377
/**
4478
* Initializes the OpenWithExternalEditor domain with its commands.
@@ -50,6 +84,7 @@ function init(domainManager) {
5084
if (!domainManager.hasDomain("OpenWithExternalApplication")) {
5185
domainManager.registerDomain("OpenWithExternalApplication", {major: 0, minor: 1});
5286
}
87+
5388
_domainManager.registerCommand(
5489
"OpenWithExternalApplication",
5590
"open",
@@ -63,6 +98,32 @@ function init(domainManager) {
6398
}],
6499
[]
65100
);
101+
102+
_domainManager.registerCommand(
103+
"OpenWithExternalApplication",
104+
"checkFileTypesInFolder",
105+
_checkFileTypesInFolder,
106+
true,
107+
"looks for File Types in a folder.",
108+
[{
109+
name: "params",
110+
type: "object",
111+
description: "Params Object having File Extensions and Folder Path."
112+
}],
113+
[]
114+
);
115+
116+
_domainManager.registerEvent(
117+
"OpenWithExternalApplication",
118+
"checkFileTypesInFolderResponse",
119+
[
120+
{
121+
name: "msgObj",
122+
type: "object",
123+
description: "json object containing message info to pass to brackets"
124+
}
125+
]
126+
);
66127
}
67128

68129
exports.init = init;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "brackets-open-external_application",
33
"dependencies": {
4-
"open": "0.0.5"
4+
"open": "0.0.5",
5+
"glob": "7.1.1"
56
}
67
}

src/nls/root/strings.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,5 +906,11 @@ define({
906906
"REMOTE_DEBUGGING_PORT_INVALID" : "Cannot enable remote debugging on port {0}. Port numbers should be between {1} and {2}.",
907907

908908
//Associate File Type to External App
909-
"DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Add File type association to external App here"
909+
"DESCRIPTION_EXTERNAL_APPLICATION_ASSOCIATE" : "Associate File type to external App settings. e.g { \"<file_type>\": \"<app_name>\" } 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.",
910+
911+
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphic Files in External Editors.",
912+
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Your current folder has graphic file types which are not supported by Brackets.<br/>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.<br/><br/>Please click on ‘Ok’ button to associate the graphic file types with their respective default applications.",
913+
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG" : "Following file types have been successfully associated with default applications.<br/>{0} You can further add new file type associations or customize in brackets.json by going to “Debug->Open Preferences File” menu."
914+
915+
910916
});

0 commit comments

Comments
 (0)