Skip to content

Commit

Permalink
detect graphics file in a project
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh Kumar committed Mar 10, 2020
1 parent 7f5f064 commit 3cbacd8
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 3 deletions.
83 changes: 83 additions & 0 deletions src/extensions/default/OpenWithExternalApplication/GraphicsFile.js
Original file line number Diff line number Diff line change
@@ -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;

});
8 changes: 7 additions & 1 deletion src/extensions/default/OpenWithExternalApplication/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -50,6 +85,7 @@ function init(domainManager) {
if (!domainManager.hasDomain("OpenWithExternalApplication")) {
domainManager.registerDomain("OpenWithExternalApplication", {major: 0, minor: 1});
}

_domainManager.registerCommand(
"OpenWithExternalApplication",
"open",
Expand All @@ -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;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "brackets-open-external_application",
"dependencies": {
"open": "0.0.5"
"open": "0.0.5",
"glob": "7.1.1"
}
}

0 comments on commit 3cbacd8

Please sign in to comment.