forked from adobe/brackets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nitesh Kumar
committed
Mar 5, 2020
1 parent
5171c85
commit 0420ac1
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* 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 AppInit = brackets.getModule("utils/AppInit"), | ||
PreferencesManager = brackets.getModule("preferences/PreferencesManager"), | ||
Strings = brackets.getModule("strings"), | ||
FileViewController = brackets.getModule("project/FileViewController"), | ||
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"), | ||
NodeDomain = brackets.getModule("utils/NodeDomain"), | ||
FileUtils = brackets.getModule("file/FileUtils"); | ||
|
||
/** | ||
* @private | ||
* @type {string} fullPath of the OpenWithExternalEditor Domain implementation | ||
*/ | ||
var _domainPath = ExtensionUtils.getModulePath(module, "node/OpenWithExternalEditorDomain"); | ||
|
||
/** | ||
* @private | ||
* @type {NodeDomain} | ||
*/ | ||
var _nodeDomain = new NodeDomain("OpenWithExternalEditor", _domainPath); | ||
|
||
var extensionToExternalEditorMap = {}; | ||
|
||
function _openInExternalEdior(event, path) { | ||
_nodeDomain.exec("open", { | ||
path: path, | ||
app: extensionToExternalEditorMap[FileUtils.getFileExtension(path).toLowerCase()] | ||
}); | ||
} | ||
|
||
PreferencesManager.definePreference("externalEditor", "object", {}, { | ||
description: Strings.DESCRIPTION_EXTERNAL_EDITOR | ||
}); | ||
|
||
PreferencesManager.on("change", "externalEditor", function () { | ||
extensionToExternalEditorMap = PreferencesManager.get("externalEditor"); | ||
}); | ||
|
||
FileViewController.on("openInExternalEditor", _openInExternalEdior); | ||
|
||
AppInit.appReady(function () { | ||
FileUtils.addExtensionToExternalAppList(Object.keys(extensionToExternalEditorMap)); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
src/extensions/default/OpenWithExternalEditor/node/OpenWithExternalEditorDomain.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2012 - 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. | ||
* | ||
*/ | ||
|
||
/*eslint-env node */ | ||
/*jslint node: true */ | ||
"use strict"; | ||
|
||
var open = require("open"); | ||
|
||
var _domainManager; | ||
|
||
/** | ||
* @private | ||
* | ||
* @param {Object} params Object to use | ||
*/ | ||
function _OpenWithExternalEditor(params) { | ||
var application = "default" === params.app ? "": params.app; | ||
open(params.path, application); | ||
} | ||
|
||
|
||
/** | ||
* Initializes the OpenWithExternalEditor domain with its commands. | ||
* @param {DomainManager} domainManager The DomainManager for the server | ||
*/ | ||
function init(domainManager) { | ||
_domainManager = domainManager; | ||
|
||
if (!domainManager.hasDomain("OpenWithExternalEditor")) { | ||
domainManager.registerDomain("OpenWithExternalEditor", {major: 0, minor: 1}); | ||
} | ||
_domainManager.registerCommand( | ||
"OpenWithExternalEditor", | ||
"open", | ||
_OpenWithExternalEditor, | ||
true, | ||
"open document with External Editor.", | ||
[{ | ||
name: "params", | ||
type: "object", | ||
description: "Params Object having document and App Path." | ||
}], | ||
[] | ||
); | ||
} | ||
|
||
exports.init = init; |
6 changes: 6 additions & 0 deletions
6
src/extensions/default/OpenWithExternalEditor/node/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "brackets-open-external_editor", | ||
"dependencies": { | ||
"open": "0.0.5" | ||
} | ||
} |