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

Commit 1d82fbe

Browse files
author
Nitesh Kumar
committed
Merge branch 'graphicsFileExternalApplication' of https://github.com/niteskum/brackets into graphicsFileExternalApplication
2 parents 8201033 + 4d7268d commit 1d82fbe

File tree

2 files changed

+78
-23
lines changed

2 files changed

+78
-23
lines changed

src/extensions/default/OpenWithExternalApplication/GraphicsFile.js

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ define(function (require, exports, module) {
2727

2828
var PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
2929
Strings = brackets.getModule("strings"),
30+
StringsUtils = brackets.getModule("utils/StringUtils"),
3031
ProjectManager = brackets.getModule("project/ProjectManager"),
3132
Dialogs = brackets.getModule("widgets/Dialogs"),
32-
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs");
33+
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
34+
HealthLogger = brackets.getModule("utils/HealthLogger");
3335

3436

3537
var _requestID = 0,
@@ -41,15 +43,15 @@ define(function (require, exports, module) {
4143

4244
function init(nodeDomain) {
4345

44-
if(_initialized) {
46+
if (_initialized) {
4547
return;
4648
}
4749
_initialized = true;
4850

4951
_nodeDomain = nodeDomain;
5052

5153
_nodeDomain.on('checkFileTypesInFolderResponse', function (event, response) {
52-
if(response.id !== _requestID) {
54+
if (response.id !== _requestID) {
5355
return;
5456
}
5557
_graphicsFilePresentInProject(response.present);
@@ -66,7 +68,7 @@ define(function (require, exports, module) {
6668

6769
function _checkForGraphicsFileInPrjct() {
6870

69-
if(PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) {
71+
if (PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) {
7072
return;
7173
}
7274

@@ -80,7 +82,7 @@ define(function (require, exports, module) {
8082

8183
function _graphicsFilePresentInProject(isPresent) {
8284

83-
if(!isPresent) {
85+
if (!isPresent) {
8486
return;
8587
}
8688

@@ -90,28 +92,66 @@ define(function (require, exports, module) {
9092
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG,
9193
[
9294
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
93-
text: Strings.BUTTON_NO
95+
text: Strings.CANCEL
9496
},
9597
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
96-
text: Strings.BUTTON_YES
98+
text: Strings.OK
9799
}
98100
]
99101
).done(function (id) {
100-
101-
if(id !== Dialogs.DIALOG_BTN_OK) {
102+
103+
if (id !== Dialogs.DIALOG_BTN_OK) {
104+
HealthLogger.sendAnalyticsData(
105+
"externalEditorsCancelled",
106+
"usage",
107+
"externalEditors",
108+
"Cancelled",
109+
""
110+
);
102111
return;
103112
}
113+
HealthLogger.sendAnalyticsData(
114+
"LinkExternalEditors",
115+
"usage",
116+
"externalEditors",
117+
"LinkExternalEditors",
118+
""
119+
);
104120

105121
brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) {
106122

107-
if(err) {
123+
if (err) {
108124
return;
109125
}
110126
var associateApp = out.split(','),
111-
fileTypeToAppMap = {};
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 !== "adobe.cc.xd") {
141+
return;
142+
}
143+
app = "Adobe XD";
144+
}
145+
fileTypeToAppMap[filetype] = app;
112146

113-
associateApp.forEach(function(item) {
114-
fileTypeToAppMap[item.split('##')[0]] = item.split('##')[1];
147+
if (brackets.platform === "win" && !app.toLowerCase().endsWith('.exe')) {
148+
app = app.substring(app.lastIndexOf('//') + 2, app.length - 4);
149+
}
150+
if (AppToFileTypeMap[app]) {
151+
AppToFileTypeMap[app].push(filetype);
152+
} else {
153+
AppToFileTypeMap[app] = [filetype];
154+
}
115155
});
116156

117157
var prefs = PreferencesManager.get('externalApplications');
@@ -120,26 +160,40 @@ define(function (require, exports, module) {
120160
if (fileTypeToAppMap.hasOwnProperty(key)) {
121161
if(key && !prefs[key]) {
122162
prefs[key] = fileTypeToAppMap[key];
123-
if(brackets.platform === "win" && !fileTypeToAppMap[key].endsWith('.exe') &&
124-
!fileTypeToAppMap[key].endsWith('.EXE')) {
163+
if(brackets.platform === "win" && !fileTypeToAppMap[key].toLowerCase().endsWith('.exe')) {
125164
prefs[key] = "default";
126165
}
166+
HealthLogger.sendAnalyticsData(
167+
"AddExternalEditorForFileType_" + key.toUpperCase(),
168+
"usage",
169+
"externalEditors",
170+
"AddExternalEditorForFileType_" + key.toUpperCase(),
171+
""
172+
);
127173
}
128174
}
129175
}
130176

131177
PreferencesManager.set('externalApplications', prefs);
132178

179+
var str = "";
180+
for(var app in AppToFileTypeMap) {
181+
str += AppToFileTypeMap[app].join() + "->" + app + "<br/>";
182+
}
183+
184+
if(!str) {
185+
return;
186+
}
187+
188+
str+="<br/>";
189+
133190
Dialogs.showModalDialog(
134191
DefaultDialogs.DIALOG_ID_INFO,
135192
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE,
136-
out,
193+
StringsUtils.format(Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_CNF_MSG, str),
137194
[
138-
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
139-
text: Strings.BUTTON_NO
140-
},
141195
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
142-
text: Strings.BUTTON_YES
196+
text: Strings.OK
143197
}
144198
]
145199
);

src/nls/root/strings.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +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.",
910910

911-
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE" : "Open Graphics Files in external editors?",
912-
"ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG" : "Click Yes to associate the graphic files with its appropriate external editors."
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."
913914

914915

915916
});

0 commit comments

Comments
 (0)