Skip to content

Commit 3c8a888

Browse files
committed
Init commit
1 parent cbbf4bd commit 3c8a888

11 files changed

Lines changed: 525 additions & 0 deletions

File tree

htmlContent/html5.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Untitled Document</title>
5+
<meta charset="UTF-8">
6+
<meta name="description" content="" />
7+
<meta name="keywords" content="" />
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>

lib/newDoc.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2012 Yasin Kuyu - twitter.com/yasinkuyu. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
*/
15+
16+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
17+
/*global define, brackets, window, $, Mustache, navigator */
18+
19+
define(function (require, exports, module) {
20+
"use strict";
21+
22+
23+
var docIndex = 1,
24+
commandId = "insya.newdoc.cmd",
25+
html5File = "insya.newhtml5";
26+
27+
// Brackets modules
28+
var DocumentManager = brackets.getModule("document/DocumentManager"),
29+
Commands = brackets.getModule("command/Commands"),
30+
CommandManager = brackets.getModule("command/CommandManager"),
31+
KeyBindingManager = brackets.getModule("command/KeyBindingManager"),
32+
EditorManager = brackets.getModule("editor/EditorManager"),
33+
Menus = brackets.getModule("command/Menus");
34+
35+
// Template file
36+
var Html5Template = require("text!htmlContent/html5.html"),
37+
Localize = require("strings");
38+
39+
// Brackets elements
40+
var sidebar = $("#sidebar"),
41+
toolbar = $("#main-toolbar");
42+
43+
// Create Untitled Document function
44+
function handleFileNew()
45+
{
46+
var doc = DocumentManager.createUntitledDocument(docIndex++, ".html");
47+
DocumentManager.setCurrentDocument(doc);
48+
EditorManager.focusEditor();
49+
doc.setText(Html5Template);
50+
51+
}
52+
53+
// Sidebar double-click event
54+
sidebar.on('dblclick', 'div', function(e) {
55+
56+
// if not children element
57+
if (e.target === this) {
58+
handleFileNew();
59+
}
60+
61+
});
62+
63+
// Toolbar double-click event
64+
toolbar.on('dblclick', function(e) {
65+
66+
// if not children element
67+
if (e.target === this) {
68+
handleFileNew();
69+
}
70+
71+
});
72+
73+
// Register command
74+
CommandManager.register(Localize.MENU_NEW_DOC, html5File, handleFileNew);
75+
76+
// Set menu
77+
var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU);
78+
menu.addMenuItem(html5File, undefined, Menus.AFTER, Commands.FILE_NEW_UNTITLED);
79+
80+
// Shortcut add binding
81+
KeyBindingManager.addBinding(commandId, "Ctrl-Alt-N", "mac");
82+
KeyBindingManager.addBinding(commandId, "Ctrl-Alt-N", "win");
83+
84+
});

lib/stringConvert.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Copyright (c) 2012 Yasin Kuyu - twitter.com/yasinkuyu. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
*/
15+
16+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
17+
/*global define, $, brackets, btoa, atob */
18+
19+
define(function (require, exports, module) {
20+
'use strict';
21+
22+
// Brackets modules
23+
var EditorManager = brackets.getModule("editor/EditorManager"),
24+
CommandManager = brackets.getModule("command/CommandManager"),
25+
Menus = brackets.getModule("command/Menus"),
26+
Localize = require("strings");
27+
28+
var STRING_REMOVE_EMPTY_LINES = "string_remove_empty_lines",
29+
STRING_REMOVE_BREAK_LINES = "string_remove_break_lines",
30+
STRING_REMOVE_LEADING_NEW_LINES = "string_remove_leading_newlines",
31+
STRING_UPPERCASE = "string_uppercase",
32+
STRING_LOWERCASE = "string_lowercase",
33+
STRING_TITLECASE = "string_titlecase",
34+
STRING_HTML_ENCODE = "string_html_encode",
35+
STRING_HTML_DECODE = "string_html_decode",
36+
STRING_ENCODE_URI = "string_encode_uri_component",
37+
STRING_DECODE_URI = "string_decode_uri_component";
38+
39+
/* Extension const */
40+
var commandId = "insya-tools",
41+
menuId = "insya-menu",
42+
moduleName = "insya-module-string";
43+
44+
// Selections
45+
function getSelectedText() {
46+
var editor = EditorManager.getFocusedEditor();
47+
if( editor ){
48+
var selection = editor.getSelection();
49+
var selectText = editor.getSelectedText();
50+
return selectText;
51+
}
52+
53+
}
54+
55+
function setSelectedText(text) {
56+
57+
var editor = EditorManager.getFocusedEditor();
58+
var selection = editor.getSelection();
59+
60+
//EditorManager.getFocusedEditor()._codeMirror.replaceSelection(text);
61+
62+
editor.document.replaceRange(text, selection.start, selection.end);
63+
}
64+
65+
// Line Operations
66+
function removeBreaklines(){
67+
68+
var result = getSelectedText().replace(/\n/g,'');
69+
setSelectedText(result);
70+
71+
}
72+
73+
function removeEmptyLines(){
74+
75+
var result = getSelectedText().replace(/^(\r\n)|(\n)/,'');
76+
setSelectedText(result);
77+
78+
}
79+
80+
function removeLeadingNewLines(){
81+
82+
var result = getSelectedText().replace(/^\n+/, "");
83+
setSelectedText(result);
84+
85+
}
86+
87+
function toUppper() {
88+
setSelectedText(getSelectedText().toUpperCase());
89+
}
90+
91+
function toLower() {
92+
setSelectedText(getSelectedText().toLowerCase());
93+
}
94+
95+
function toTitle() {
96+
setSelectedText(getSelectedText().toLowerCase());
97+
}
98+
99+
function urlEncode() {
100+
setSelectedText(encodeURIComponent(getSelectedText()));
101+
}
102+
103+
function urlDecode() {
104+
setSelectedText(decodeURIComponent(getSelectedText()));
105+
}
106+
107+
function htmlEncode() {
108+
var result = getSelectedText().replace(/"/g, "&quot;").replace(/'/g, "&#39;");
109+
setSelectedText(result);
110+
}
111+
112+
function htmlDecode() {
113+
var result = getSelectedText();
114+
setSelectedText(result);
115+
}
116+
117+
function createNavigation(menu) {
118+
menu.addMenuItem(STRING_REMOVE_EMPTY_LINES);
119+
menu.addMenuItem(STRING_REMOVE_BREAK_LINES);
120+
menu.addMenuItem(STRING_REMOVE_LEADING_NEW_LINES);
121+
menu.addMenuDivider();
122+
menu.addMenuItem(STRING_UPPERCASE);
123+
menu.addMenuItem(STRING_LOWERCASE);
124+
menu.addMenuItem(STRING_TITLECASE);
125+
menu.addMenuDivider();
126+
menu.addMenuItem(STRING_HTML_ENCODE);
127+
menu.addMenuItem(STRING_HTML_DECODE);
128+
menu.addMenuDivider();
129+
menu.addMenuItem(STRING_ENCODE_URI);
130+
menu.addMenuItem(STRING_DECODE_URI);
131+
}
132+
133+
CommandManager.register(Localize.STRING_REMOVE_EMPTY_LINES, STRING_REMOVE_EMPTY_LINES, removeEmptyLines);
134+
CommandManager.register(Localize.STRING_REMOVE_BREAK_LINES, STRING_REMOVE_BREAK_LINES, removeBreaklines);
135+
CommandManager.register(Localize.STRING_REMOVE_LEADING_NEW_LINES, STRING_REMOVE_LEADING_NEW_LINES, removeLeadingNewLines);
136+
137+
CommandManager.register(Localize.STRING_UPPERCASE, STRING_UPPERCASE, toUppper);
138+
CommandManager.register(Localize.STRING_LOWERCASE, STRING_LOWERCASE, toLower);
139+
CommandManager.register(Localize.STRING_TITLECASE, STRING_TITLECASE, toTitle);
140+
141+
CommandManager.register(Localize.STRING_HTML_ENCODE, STRING_HTML_ENCODE, htmlEncode);
142+
CommandManager.register(Localize.STRING_HTML_DECODE, STRING_HTML_DECODE, htmlDecode);
143+
144+
CommandManager.register(Localize.STRING_ENCODE_URI, STRING_ENCODE_URI, urlEncode);
145+
CommandManager.register(Localize.STRING_DECODE_URI, STRING_DECODE_URI, urlDecode);
146+
147+
//var menu = Menus.getMenu(Menus.AppMenuBar.EDIT_MENU);
148+
var menu = Menus.addMenu(Localize.MENU_LABEL, commandId, Menus.BEFORE, Menus.AppMenuBar.HELP_MENU);
149+
createNavigation(menu);
150+
151+
var contextMenu = Menus.getContextMenu(Menus.ContextMenuIds.EDITOR_MENU);
152+
createNavigation(contextMenu);
153+
154+
});

lib/wordHighlight.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2012 Yasin Kuyu - twitter.com/yasinkuyu. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
*/
15+
16+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
17+
/*global define, $, brackets, window */
18+
19+
/** Simple extension that adds a "File > Hello World" menu item */
20+
define(function (require, exports, module) {
21+
"use strict";
22+
23+
var EditorManager = brackets.getModule("editor/EditorManager"),
24+
Menus = brackets.getModule("command/Menus"),
25+
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
26+
Localize = require("strings");
27+
28+
29+
/* Extension const */
30+
var commandId = "insya-highlighter",
31+
moduleName = "insya-module-highlighter",
32+
prefs = PreferencesManager.getExtensionPrefs(moduleName);
33+
34+
35+
prefs.definePreference("enabled", "boolean", false);
36+
var isEnabled = prefs.get("enabled");
37+
38+
function attachHighlighter(){
39+
$(EditorManager).on("activeEditorChange", function(e, activeEditor, prevEditor){
40+
setEditorHighlighted(activeEditor, true);
41+
setEditorHighlighted(prevEditor, false);
42+
});
43+
}
44+
45+
function setEditorHighlighted(editor, enabled){
46+
if (!editor) {
47+
return;
48+
}
49+
50+
var cm = editor._codeMirror;
51+
cm.setOption("highlightSelectionMatches", (isEnabled && enabled) ? {showToken:true}: false);
52+
}
53+
54+
function toggleHighlighter(){
55+
var editor = EditorManager.getActiveEditor();
56+
57+
isEnabled = !isEnabled;
58+
prefs.set("enabled", isEnabled);
59+
prefs.save();
60+
61+
setEditorHighlighted(editor, true);
62+
setChecked(isEnabled);
63+
}
64+
65+
function registerCommand(){
66+
var CommandManager = brackets.getModule("command/CommandManager");
67+
var command = CommandManager.register(Localize.VIEW_HIGHLIGHT, commandId, toggleHighlighter);
68+
command.setChecked(isEnabled);
69+
70+
var menu = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU);
71+
menu.addMenuItem(Menus.DIVIDER);
72+
menu.addMenuItem(commandId);
73+
}
74+
75+
attachHighlighter();
76+
registerCommand();
77+
78+
});

main.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2012 Yasin Kuyu - twitter.com/yasinkuyu. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
*/
15+
16+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */
17+
/*global define, brackets, window, $, Mustache, navigator */
18+
19+
define(function (require, exports, module) {
20+
"use strict";
21+
22+
// Brackets modules
23+
var PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
24+
Commands = brackets.getModule("command/Commands"),
25+
CommandManager = brackets.getModule("command/CommandManager"),
26+
ExtensionUtils = brackets.getModule("utils/ExtensionUtils"),
27+
Strings = brackets.getModule("strings"),
28+
StringUtils = brackets.getModule("utils/StringUtils"),
29+
Menus = brackets.getModule("command/Menus"),
30+
DefaultDialogs = brackets.getModule("widgets/DefaultDialogs"),
31+
Dialogs = brackets.getModule("widgets/Dialogs"),
32+
wordHighlight = require("lib/wordHighlight"),
33+
newDocument = require("lib/newDoc"),
34+
stringConvert = require("lib/stringConvert"),
35+
Localize = require("strings");
36+
37+
/* Extension const */
38+
var commandId = "insya-command",
39+
menuId = "insya-menu",
40+
moduleName = "insya-module";
41+
42+
/* Extension's preferences */
43+
var prefs = PreferencesManager.getExtensionPrefs(moduleName);
44+
45+
// ExtensionUtils.loadStyleSheet(module, "styles/styles.css");
46+
// More tools coming soon...
47+
48+
});

0 commit comments

Comments
 (0)