-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
245 lines (205 loc) · 9.03 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
define(function (require, exports, module)
{
"use strict";
var EditorManager = brackets.getModule("editor/EditorManager"),
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
Strings = brackets.getModule("strings"),
DocumentManager = brackets.getModule("document/DocumentManager"),
MainViewManager = brackets.getModule("view/MainViewManager"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
DocumentModule = brackets.getModule("document/Document"),
InMemoryFile = brackets.getModule("document/InMemoryFile"),
Editor = brackets.getModule("editor/Editor"),
QuickFormToolTemplate = require("text!ui/QuickFormToolTemplate.html"),
Mustache_ = brackets.getModule("thirdparty/mustache/mustache")
var untitledhtml5index = 1;
var untitledcssindex = 1;
var untitledjsindex = 1;
function quickFormToolProvider()
{
try
{
var $element = $(Mustache_.render(QuickFormToolTemplate, Strings));
$element.find(".qft-form").click(function () { quickFormTool("form"); });
$element.find(".qft-button").click(function () { quickFormTool("button"); });
$element.find(".qft-textfield").click(function () { quickFormTool("textfield"); });
$element.find(".qft-filefield").click(function () { quickFormTool("filefield"); });
$element.find(".qft-checkbox").click(function () { quickFormTool("checkbox"); });
$element.find(".qft-radiobutton").click(function () { quickFormTool("radiobutton"); });
$element.find(".qft-hiddenfield").click(function () { quickFormTool("hiddenfield"); });
$element.find(".qft-textarea").click(function () { quickFormTool("textarea"); });
$element.find(".qft-imagefield").click(function () { quickFormTool("imagefield"); });
$element.find(".qft-imagebutton").click(function () { quickFormTool("imagebutton"); });
$element.find(".qft-listmenu").click(function () { quickFormTool("listmenu"); });
$element.find(".qft-link").click(function () { quickFormTool("link"); });
$element.find(".qft-html5audio").click(function () { quickFormTool("html5audio"); });
$element.find(".qft-html5video").click(function () { quickFormTool("html5video"); });
$element.find(".qft-embedflash").click(function () { quickFormTool("embedflash"); });
$element.find(".qft-html5file").click(function () { quickFormTool("html5file"); });
$element.find(".qft-cssfile").click(function () { quickFormTool("cssfile"); });
$element.find(".qft-jsfile").click(function () { quickFormTool("jsfile"); });
$element.find(".qftnotify").click(function () { $element.find(".qftblock").toggleClass("qftblock-exp");
$element.find(".qftnotify").toggleClass("qftnotify-exp"); });
$element.find(".qft-unpin").click(function () {$element.find(".qftblock").toggleClass("qftblock-exp");
$element.find(".qft-unpin").toggleClass("qft-pin"); });
$($element).insertBefore("#editor-holder");
}
catch(e)
{
alert("Error: " + e);
}
}
var loadfunction = quickFormToolProvider();
function quickFormTool(_class)
{
try
{
if (true)
{
switch (_class)
{
case "form":
handleText("<form action=\"\" method=\"post\"></form>");
break;
case "textfield":
handleText("<input type=\"text\" name=\"textfield\" placeholder=\"TextField\">");
break;
case "textarea":
handleText("<textarea name=\"textarea\" placeholder=\"TextArea\"></textarea>");
break;
case "button":
handleText("<input type=\"button\" name=\"button\">");
break;
case "checkbox":
handleText("<input type=\"checkbox\" name=\"checkbox\">");
break;
case "radiobutton":
handleText("<input type=\"radio\" name=\"radio1\">");
break;
case "listmenu":
handleText("<select name=\"selectoptions\">\n\t<option value=\"option1\">Option 1</option>\n\t<option value=\"option2\">Option 2</option>\n</select>");
break;
case "imagebutton":
handleText("<input type=\"image\" name=\"imageinput\" src=\"\" width=\"\" height=\"\">");
break;
case "imagefield":
handleText("<img src=\"\" alt=\"\" width=\"\" height=\"\">");
break;
case "filefield":
handleText("<input type=\"file\" name=\"fileinput\">");
break;
case "hiddenfield":
handleText("<input type=\"hidden\" name=\"hiddeninput\" value=\"hiddeninputvalue\">");
break;
case "link":
handleText("<a href=\"\" target=\"_self\"></a>");
break;
case "html5audio":
handleText("<audio controls>\n\t<source src=\"audio.ogg\" type=\"audio/ogg\">\n\t<source src=\"audio.mp3\" type=\"audio/mpeg\">\n\tYour browser does not support the audio element.\n</audio> ");
break;
case "html5video":
handleText("<video width=\"320\" height=\"240\" controls>\n\t<source src=\"movie.mp4\" type=\"video/mp4\">\n\t<source src=\"movie.ogg\" type=\"video/ogg\">\n\tYour browser does not support the video tag.\n</video>");
break;
case "embedflash":
handleText("<object data=\"flashfile.swf\" width=\"\" height=\"\"></object>");
break;
case "html5file":
makeHTML5File();
break;
case "cssfile":
makeCSSFile();
break;
case "jsfile":
makeJSFile();
break;
}
}
}
catch(e)
{
alert("Error: " + e);
}
};
function makeHTML5File()
{
var doc = createUntitledDocument("Untitled-", untitledhtml5index++, ".html");
handleFileNew(doc);
handleText("<!DOCTYPE html>\n<html>\n<head>\n\t<meta charset=\"UTF-8\">\n\t<title>Untitled Document</title>\n\t\n</head>\n<body>\n\t\n</body>\n</html>");
EditorManager.getActiveEditor().setCursorPos({ line: 8, pos: 0 });
}
function makeCSSFile()
{
var doc = createUntitledDocument("css", untitledcssindex, ".css");
handleTextToTag("<link rel=\"stylesheet\" href=\"css" + untitledcssindex++ + ".css\">", "head");
handleFileNew(doc);
handleText("html\n{\n\t\n\}\n");
}
function makeJSFile()
{
var doc = createUntitledDocument("javascript", untitledjsindex, ".js");
handleText("<script type=\"javascript\" src=\"javascript" + untitledjsindex++ + ".js\" />");
handleFileNew(doc);
handleText("");
}
function handleText(commandString)
{
try
{
var activeEditor = EditorManager.getActiveEditor(),
activeDoc = activeEditor && activeEditor.document,
fileFullPath = activeDoc.file.fullPath,
fileFullName = fileFullPath.substring(fileFullPath.lastIndexOf("/") + 1),
fileFormat = fileFullName.substring(fileFullName.lastIndexOf(".") + 1);
if (fileFormat != "css")
{
var line = activeEditor.document.getLine(activeEditor.getCursorPos().line);
if (line.replace(/^\s+|\s+$/g, '').length>0)
{
var csIndent = line.match(/^\s{0,32}/)[0].length;
if (line.substr(activeEditor.getCursorPos().ch).length==0)
commandString = "\n" + new Array(csIndent+1).join(' ') +commandString;
}
activeEditor.document.replaceRange(commandString, activeEditor.getCursorPos());
}
}
catch(err){}
}
function handleTextToTag(text, tag)
{
try
{
var activeEditor = EditorManager.getActiveEditor(),
activeDoc = activeEditor && activeEditor.document,
fileFullPath = activeDoc.file.fullPath,
fileFullName = fileFullPath.substring(fileFullPath.lastIndexOf("/") + 1),
fileFormat = fileFullName.substring(fileFullName.lastIndexOf(".") + 1);
EditorManager.getFocusedEditor();
var getDocumentText_ = activeEditor.document.getText().replace("</" + tag + ">", "\t" + text + "\n</" + tag + ">");
activeEditor.document.setText(getDocumentText_);
//activeEditor.document.replaceRange(text, activeEditor.getCursorPos());
}
catch(err){alert("Error: "+err);}
}
//make new document. used of document/DocumentManager -> createUntitledDocument()
function createUntitledDocument(filename, counter, fileExt) {
var fullfilename = filename + counter + fileExt,
fullPath = DocumentManager._untitledDocumentPath + "/" + fullfilename,
now = new Date(),
file = new InMemoryFile(fullPath, FileSystem);
FileSystem.addEntryForPathIfRequired(file, fullPath);
return new DocumentManager.Document(file, now, "");
}
//make new file.
function handleFileNew(docname)
{
try
{
var doc_ = docname;
MainViewManager._edit(MainViewManager.ACTIVE_PANE, doc_);
return new $.Deferred().resolve(doc_).promise();
}
catch(err){alert("Error: "+err);}
}
ExtensionUtils.loadStyleSheet(module, "ui/style.css");
exports.quickFormToolProvider = quickFormToolProvider;
});