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

Commit e8a829c

Browse files
author
Nitesh Kumar
committed
changes to detect graphics file in a project
1 parent 7d138df commit e8a829c

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

src/extensions/default/OpenWithExternalApplication/GraphicsFile.js

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ define(function (require, exports, module) {
2727

2828
var PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
2929
Strings = brackets.getModule("strings"),
30-
ProjectManager = brackets.getModule("project/ProjectManager");
30+
ProjectManager = brackets.getModule("project/ProjectManager"),
31+
Dialogs = brackets.getModule("widgets/Dialogs"),
32+
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs");
3133

3234

3335
var _requestID = 0,
3436
_initialized = false;
3537

3638
var _graphicsFileTypes = ["jpg", "jpeg", "png", "svg", "xd", "psd", "ai"];
39+
//var _graphicsFileTypes = [ "psd"];
3740

3841
var _nodeDomain;
3942

@@ -64,6 +67,10 @@ define(function (require, exports, module) {
6467

6568
function _checkForGraphicsFileInPrjct() {
6669

70+
if(PreferencesManager.getViewState("AssociateGraphicsFileDialogShown")) {
71+
return;
72+
}
73+
6774
_nodeDomain.exec("checkFileTypesInFolder", {
6875
extensions: _graphicsFileTypes.join(),
6976
folder: ProjectManager.getProjectRoot().fullPath,
@@ -74,7 +81,50 @@ define(function (require, exports, module) {
7481

7582
function _graphicsFilePresentInProject(isPresent) {
7683

77-
console.log("Graphics File present in project", isPresent);
84+
if(!isPresent) {
85+
return;
86+
}
87+
88+
Dialogs.showModalDialog(
89+
DefaultDialogs.DIALOG_ID_INFO,
90+
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE,
91+
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_MSG,
92+
[
93+
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
94+
text: Strings.BUTTON_NO
95+
},
96+
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
97+
text: Strings.BUTTON_YES
98+
}
99+
]
100+
).done(function (id) {
101+
102+
if(id !== Dialogs.DIALOG_BTN_OK)
103+
return;
104+
105+
brackets.app.getSystemDefaultApp(_graphicsFileTypes.join(), function (err, out) {
106+
var associateApp = out.split(','),
107+
fileTypeToAppMap = {};
108+
109+
associateApp.forEach(function(item) {
110+
fileTypeToAppMap[item.split(':')[0]] = item.split(':')[1]
111+
});
112+
Dialogs.showModalDialog(
113+
DefaultDialogs.DIALOG_ID_INFO,
114+
Strings.ASSOCIATE_GRAPHICS_FILE_TO_DEFAULT_APP_TITLE,
115+
out,
116+
[
117+
{ className: Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL,
118+
text: Strings.BUTTON_NO
119+
},
120+
{ className: Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK,
121+
text: Strings.BUTTON_YES
122+
}
123+
]
124+
)
125+
});
126+
});
127+
PreferencesManager.setViewState("AssociateGraphicsFileDialogShown", true);
78128

79129
}
80130

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ function _checkFileTypesInFolder(params) {
5151
var extList = params.extensions,
5252
dirPath = path.normalize(params.folder),
5353

54-
pattern = dirPath + "/**/*.+(" + extList.replace(",", "|") + ")";
55-
//pattern = dirPath + "/**/*.jpg";
54+
pattern = dirPath + "/**/*.+(" + extList.replace(/,/g, "|") + ")";
5655

57-
var mg = new Glob(pattern, function (err, matches) {
56+
var globMgr = new Glob(pattern, function (err, matches) {
5857

5958
var respObj = {
6059
id: params.reqId,
@@ -63,13 +62,13 @@ function _checkFileTypesInFolder(params) {
6362
_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
6463
});
6564

66-
mg.on("match", function() {
67-
//mg.abort();
65+
globMgr.on("match", function() {
66+
globMgr.abort();
6867
var respObj = {
6968
id: params.reqId,
7069
present: true
7170
}
72-
//_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
71+
_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
7372
});
7473

7574
}

src/nls/root/strings.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,5 +906,10 @@ 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" : "Add File type association to external App here",
910+
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."
913+
914+
910915
});

0 commit comments

Comments
 (0)