-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
54 lines (46 loc) · 1.74 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
define(function (require, exports, module) {
"use strict";
var docIndex = 1,
commandId = "new-zurbfoundation-page",
menuID = "zf.menuID",
menuLabel = "New Zurb Foundation Document",
DocumentManager = brackets.getModule("document/DocumentManager"),
Commands = brackets.getModule("command/Commands"),
CommandManager = brackets.getModule("command/CommandManager"),
KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
EditorManager = brackets.getModule("editor/EditorManager"),
MainViewManager = brackets.getModule("view/MainViewManager"),
Menus = brackets.getModule("command/Menus"),
bootstrapTemplate = require("text!template/basic.html"),
sidebar = $("#sidebar"),
toolbar = $("#main-toolbar"),
menu;
function templateHandle(templateContent) {
try {
var activeEditor = EditorManager.getActiveEditor();
activeEditor.document.replaceRange(templateContent, activeEditor.getCursorPos());
} catch (err) {}
}
function newFileHandle() {
var defaultExtension = ".html",
doc = DocumentManager.createUntitledDocument(docIndex++, defaultExtension);
MainViewManager._edit(MainViewManager.ACTIVE_PANE, doc);
templateHandle(bootstrapTemplate);
return new $.Deferred().resolve(doc).promise();
}
sidebar.on('dblclick', 'div', function (e) {
if (e.target === this) {
newFileHandle();
}
});
toolbar.on('dblclick', function (e) {
if (e.target === this) {
newFileHandle();
}
});
CommandManager.register(menuLabel, menuID, newFileHandle);
menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
menu.addMenuItem(menuID, undefined, Menus.AFTER, Commands.FILE_NEW_UNTITLED);
KeyBindingManager.addBinding(menuID, "Ctrl-Alt-Z", "mac");
KeyBindingManager.addBinding(menuID, "Ctrl-Alt-Z", "win");
});