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

Commit 3cbacd8

Browse files
author
Nitesh Kumar
committed
detect graphics file in a project
1 parent 7f5f064 commit 3cbacd8

File tree

4 files changed

+155
-3
lines changed

4 files changed

+155
-3
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
ProjectManager = brackets.getModule("project/ProjectManager");
31+
32+
33+
var _requestID = 0,
34+
_initialized = false;
35+
36+
var _graphicsFileTypes = ["jpg", "jpeg", "png", "svg", "xd", "psd", "ai"];
37+
38+
var _nodeDomain;
39+
40+
function init(nodeDomain) {
41+
42+
if(_initialized) {
43+
return;
44+
}
45+
_initialized = true;
46+
47+
_nodeDomain = nodeDomain;
48+
49+
_nodeDomain.on('checkFileTypesInFolderResponse', function (event, response) {
50+
if(response.id !== _requestID) {
51+
return;
52+
}
53+
_graphicsFilePresentInProject(response.present)
54+
});
55+
56+
ProjectManager.on("projectOpen", function () {
57+
_checkForGraphicsFileInPrjct();
58+
});
59+
60+
_checkForGraphicsFileInPrjct();
61+
62+
}
63+
64+
65+
function _checkForGraphicsFileInPrjct() {
66+
67+
_nodeDomain.exec("checkFileTypesInFolder", {
68+
extensions: _graphicsFileTypes.join(),
69+
folder: ProjectManager.getProjectRoot().fullPath,
70+
reqId: ++_requestID
71+
});
72+
73+
}
74+
75+
function _graphicsFilePresentInProject(isPresent) {
76+
77+
console.log("Graphics File present in project", isPresent);
78+
79+
}
80+
81+
exports.init = init;
82+
83+
});

src/extensions/default/OpenWithExternalApplication/main.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ define(function (require, exports, module) {
2929
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
3030
Strings = brackets.getModule("strings"),
3131
FileViewController = brackets.getModule("project/FileViewController"),
32+
ProjectManager = brackets.getModule("project/ProjectManager"),
3233
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
3334
NodeDomain = brackets.getModule("utils/NodeDomain"),
34-
FileUtils = brackets.getModule("file/FileUtils");
35+
FileUtils = brackets.getModule("file/FileUtils"),
36+
GraphicsFile = require("GraphicsFile");
3537

3638
/**
3739
* @private
@@ -47,6 +49,8 @@ define(function (require, exports, module) {
4749

4850
var extensionToExtApplicationMap = {};
4951

52+
var graphicsFileTypes = [".jpg", ".jpeg", ".png", ".svg", ".xd", ".psd", ".ai"];
53+
5054
function _openWithExternalApplication(event, path) {
5155
_nodeDomain.exec("open", {
5256
path: path,
@@ -66,6 +70,8 @@ define(function (require, exports, module) {
6670
FileViewController.on("openWithExternalApplication", _openWithExternalApplication);
6771

6872
AppInit.appReady(function () {
73+
74+
GraphicsFile.init(_nodeDomain);
6975
extensionToExtApplicationMap = PreferencesManager.get("externalApplications");
7076
FileUtils.addExtensionToExternalAppList(Object.keys(extensionToExtApplicationMap));
7177
});

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

Lines changed: 63 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,39 @@ 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(",", "|") + ")";
55+
//pattern = dirPath + "/**/*.jpg";
56+
57+
var mg = new Glob(pattern, function (err, matches) {
58+
59+
var respObj = {
60+
id: params.reqId,
61+
present: matches.length > 0 ? true : false
62+
}
63+
_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
64+
});
65+
66+
mg.on("match", function() {
67+
//mg.abort();
68+
var respObj = {
69+
id: params.reqId,
70+
present: true
71+
}
72+
//_domainManager.emitEvent('OpenWithExternalApplication', 'checkFileTypesInFolderResponse', [respObj]);
73+
});
74+
75+
}
76+
4277

4378
/**
4479
* Initializes the OpenWithExternalEditor domain with its commands.
@@ -50,6 +85,7 @@ function init(domainManager) {
5085
if (!domainManager.hasDomain("OpenWithExternalApplication")) {
5186
domainManager.registerDomain("OpenWithExternalApplication", {major: 0, minor: 1});
5287
}
88+
5389
_domainManager.registerCommand(
5490
"OpenWithExternalApplication",
5591
"open",
@@ -63,6 +99,32 @@ function init(domainManager) {
6399
}],
64100
[]
65101
);
102+
103+
_domainManager.registerCommand(
104+
"OpenWithExternalApplication",
105+
"checkFileTypesInFolder",
106+
_checkFileTypesInFolder,
107+
true,
108+
"looks for File Types in a folder.",
109+
[{
110+
name: "params",
111+
type: "object",
112+
description: "Params Object having File Extensions and Folder Path."
113+
}],
114+
[]
115+
);
116+
117+
_domainManager.registerEvent(
118+
"OpenWithExternalApplication",
119+
"checkFileTypesInFolderResponse",
120+
[
121+
{
122+
name: "msgObj",
123+
type: "object",
124+
description: "json object containing message info to pass to brackets"
125+
}
126+
]
127+
);
66128
}
67129

68130
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
}

0 commit comments

Comments
 (0)