-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.js
More file actions
119 lines (88 loc) · 4.32 KB
/
Copy pathmain.js
File metadata and controls
119 lines (88 loc) · 4.32 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
define(function (require, exports, module) {
"use strict";
var CommandManager = brackets.getModule("command/CommandManager");
var Menus = brackets.getModule("command/Menus");
var EditorManager = brackets.getModule("editor/EditorManager");
var right_click_cut = "RightClickExtended.CutHandler";
var right_click_copy = "RightClickExtended.CopyHandler";
var right_click_paste = "RightClickExtended.PasteHandler";
var NodeConnection = brackets.getModule("utils/NodeConnection");
var ExtensionUtils = brackets.getModule("utils/ExtensionUtils");
var AppInit = brackets.getModule("utils/AppInit");
var bracketsStrings = brackets.getModule("strings")
var nodeConnection = new NodeConnection();
function chain() {
var functions = Array.prototype.slice.call(arguments, 0);
if (functions.length > 0) {
var firstFunction = functions.shift();
var firstPromise = firstFunction.call();
firstPromise.done(function () {
chain.apply(null, functions);
});
}
}
AppInit.appReady(function () {
function connect() {
var connectionPromise = nodeConnection.connect(true);
connectionPromise.fail(function () {
console.error("[brackets-simple-node] failed to connect to node");
});
return connectionPromise;
}
function loadClipboard() {
var path = ExtensionUtils.getModulePath(module, "node/clipboard");
var loadPromise = nodeConnection.loadDomains([path], true);
loadPromise.fail(function (e) {
console.log(e);
console.log("[brackets-simple-node] failed to load clipboard");
});
return loadPromise;
}
function clipboardLoad() {
var loadPromise = nodeConnection.domains.clipboard.load();
loadPromise.fail(function (err) {
console.error("[brackets-simple-node] failed to run clipboard.load", err);
});
loadPromise.done(function (err) {
//loaded
});
return loadPromise;
}
chain(connect, loadClipboard, clipboardLoad);
});
$(nodeConnection).on("clipboard.paste", function (e, clipboardContent) {
var thisEditor = EditorManager.getCurrentFullEditor();
var cp = thisEditor._codeMirror.getCursor();
thisEditor._codeMirror.replaceSelection(clipboardContent.content);
//move cursor to end of pasted content
cp.ch += clipboardContent.content.length;
thisEditor._codeMirror.setCursor(cp);
});
//Function to run when the menu item is clicked
function handleRightClickPaste() {
//Paste text
nodeConnection.domains.clipboard.callPaste();
}
function handleRightClickCopy() {
var thisEditor = EditorManager.getCurrentFullEditor();
//check selection is not blank
if(thisEditor._codeMirror.getSelection().trim() != ''){
nodeConnection.domains.clipboard.callCopy(thisEditor._codeMirror.getSelection());
}
}
function handleRightClickCut() {
var thisEditor = EditorManager.getCurrentFullEditor();
var cp = thisEditor._codeMirror.getCursor();
nodeConnection.domains.clipboard.callCopy(thisEditor._codeMirror.getSelection());
thisEditor._codeMirror.replaceSelection('');
//thisEditor._codeMirror.setCursor(cp);
}
CommandManager.register(bracketsStrings.CMD_CUT, right_click_cut, handleRightClickCut);
CommandManager.register(bracketsStrings.CMD_COPY, right_click_copy, handleRightClickCopy);
CommandManager.register(bracketsStrings.CMD_PASTE, right_click_paste, handleRightClickPaste);
Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU).addMenuDivider();
Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU).addMenuItem(right_click_cut);
Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU).addMenuItem(right_click_copy);
Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU).addMenuItem(right_click_paste);
//exports.handleRightClickExtended = handleRightClickExtended;
});