This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.js
70 lines (57 loc) · 2.36 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
define(function (require, exports, module) {
"use strict";
var FILE_EXT = ".vue",
MENU_LABEL = "New *.vue",
EXTENSION_NAME = "Brackets Vue",
VUE_CREATE_EXECUTE = "vue.create.execute",
VUE_MODE_FILE_PATH = "/thirdparty/CodeMirror/mode/vue/vue.js",
documentIndex = 1,
Menus = brackets.getModule("command/Menus"),
AppInit = brackets.getModule("utils/AppInit"),
Commands = brackets.getModule("command/Commands"),
FileUtils = brackets.getModule("file/FileUtils"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
EditorManager = brackets.getModule("editor/EditorManager"),
CommandManager = brackets.getModule("command/CommandManager"),
DocumentManager = brackets.getModule("document/DocumentManager"),
MainViewManager = brackets.getModule("view/MainViewManager"),
LanguageManager = brackets.getModule("language/LanguageManager");
function createVueComponentFile() {
var templateContent = require("text!./template.vue"),
document = DocumentManager.createUntitledDocument(documentIndex++, FILE_EXT);
MainViewManager._edit(MainViewManager.ACTIVE_PANE, document);
try {
var activeEditor = EditorManager.getActiveEditor();
activeEditor.document.replaceRange(
templateContent,
activeEditor.getCursorPos()
);
} catch(e) {
console.log(EXTENSION_NAME + " createVueComponentFile() : ", e);
}
return new $.Deferred().resolve(document).promise();
}
function setLanguage(mode) {
LanguageManager.defineLanguage("vue", {
name : "Vue component file",
mode : mode,
fileExtensions : ["vue"]
});
}
var file = FileSystem.getFileForPath(
FileUtils.getNativeBracketsDirectoryPath() + VUE_MODE_FILE_PATH
);
file.exists(function (err, exists) {
setLanguage((!err && exists) ? "vue" : "htmlmixed");
});
AppInit.appReady(function () {
CommandManager.register(MENU_LABEL, VUE_CREATE_EXECUTE, createVueComponentFile);
var fileMenu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
fileMenu.addMenuItem(
VUE_CREATE_EXECUTE,
undefined,
Menus.AFTER,
Commands.FILE_NEW_UNTITLED
);
});
});