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

Commit 5171c85

Browse files
author
Nitesh Kumar
committed
Associate an file tpye to external Application
1 parent 3ae5417 commit 5171c85

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

src/file/FileUtils.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ define(function (require, exports, module) {
5959
*/
6060
var MAX_FILE_SIZE = MAX_FILE_SIZE_MB * 1024 * 1024;
6161

62+
/**
63+
* @const {List} list of File Extensions which will be opened in external Application
64+
*/
65+
var extListToBeOpenedInExtApp = [];
66+
6267

6368
/**
6469
* Asynchronously reads a file as UTF-8 encoded text.
@@ -526,6 +531,28 @@ define(function (require, exports, module) {
526531
return pathArray.join("/");
527532
}
528533

534+
/**
535+
* @param {string} ext extension string a file
536+
* @return {string} returns true If file to be opened in External Application.
537+
*
538+
*/
539+
function shouldOpenInExternalApplication(ext) {
540+
return !extListToBeOpenedInExtApp.includes(ext);
541+
}
542+
543+
/**
544+
* @param {string} ext File Extensions to be added in External App List
545+
*
546+
*/
547+
function addExtensionToExternalAppList(ext) {
548+
549+
if(typeof ext !== 'string') {
550+
extListToBeOpenedInExtApp.concat(ext);
551+
} else {
552+
extListToBeOpenedInExtApp.push(ext);
553+
}
554+
}
555+
529556
// Asynchronously load DocumentCommandHandlers
530557
// This avoids a temporary circular dependency created
531558
// by relocating showFileOpenError() until deprecation is over
@@ -568,4 +595,6 @@ define(function (require, exports, module) {
568595
exports.comparePaths = comparePaths;
569596
exports.MAX_FILE_SIZE = MAX_FILE_SIZE;
570597
exports.encodeFilePath = encodeFilePath;
598+
exports.shouldOpenInExternalApplication = shouldOpenInExternalApplication;
599+
exports.addExtensionToExternalAppList = addExtensionToExternalAppList;
571600
});

src/nls/root/strings.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,5 +903,8 @@ define({
903903
"REMOTE_DEBUGGING_ENABLED" : "Remote debugging enabled on localhost:",
904904

905905
// Remote debugging port argument is invalid
906-
"REMOTE_DEBUGGING_PORT_INVALID" : "Cannot enable remote debugging on port {0}. Port numbers should be between {1} and {2}."
906+
"REMOTE_DEBUGGING_PORT_INVALID" : "Cannot enable remote debugging on port {0}. Port numbers should be between {1} and {2}.",
907+
908+
//Associate File Type to External App
909+
"DESCRIPTION_EXTERNAL_EDITOR" : "Add File type association to external App here"
907910
});

src/project/FileTreeView.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ define(function (require, exports, module) {
3939
LanguageManager = require("language/LanguageManager"),
4040
FileTreeViewModel = require("project/FileTreeViewModel"),
4141
ViewUtils = require("utils/ViewUtils"),
42-
KeyEvent = require("utils/KeyEvent");
42+
KeyEvent = require("utils/KeyEvent"),
43+
PreferencesManager = require("preferences/PreferencesManager");
4344

4445
var DOM = Preact.DOM;
4546

@@ -554,7 +555,10 @@ define(function (require, exports, module) {
554555
});
555556
}
556557
} else {
557-
this.props.actions.setSelected(this.myPath());
558+
this.props.actions.setSelected(this.myPath(),
559+
FileUtils.shouldOpenInExternalApplication(
560+
FileUtils.getFileExtension(this.myPath()).toLowerCase()
561+
));
558562
}
559563
e.stopPropagation();
560564
e.preventDefault();
@@ -569,6 +573,12 @@ define(function (require, exports, module) {
569573
if (this.state.clickTimer !== null) {
570574
this.clearTimer();
571575
}
576+
if (FileUtils.shouldOpenInExternalApplication(
577+
FileUtils.getFileExtension(this.myPath()).toLowerCase()
578+
)) {
579+
this.props.actions.openInExternalEditor(this.myPath());
580+
return;
581+
}
572582
this.props.actions.selectInWorkingSet(this.myPath());
573583
}
574584
},

src/project/FileViewController.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ define(function (require, exports, module) {
226226
return result.promise();
227227
}
228228

229+
/**
230+
* Opens the specified document with its associated external editor,
231+
*/
232+
function openInExternalEditor(fullPath) {
233+
exports.trigger("openInExternalEditor", fullPath);
234+
}
235+
229236
/**
230237
* Opens the specified document if it's not already open, adds it to the working set,
231238
* and selects it in the WorkingSetView
@@ -275,4 +282,5 @@ define(function (require, exports, module) {
275282
exports.setFileViewFocus = setFileViewFocus;
276283
exports.WORKING_SET_VIEW = WORKING_SET_VIEW;
277284
exports.PROJECT_MANAGER = PROJECT_MANAGER;
285+
exports.openInExternalEditor = openInExternalEditor;
278286
});

src/project/ProjectManager.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ define(function (require, exports, module) {
280280
this.model.selectInWorkingSet(path);
281281
};
282282

283+
/**
284+
* See `FileViewController.openInExternalEditor`
285+
*/
286+
ActionCreator.prototype.openInExternalEditor = function (path) {
287+
FileViewController.openInExternalEditor(path);
288+
};
289+
290+
283291
/**
284292
* See `ProjectModel.setContext`
285293
*/

0 commit comments

Comments
 (0)