forked from g2384/VHDLFormatter
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.ts
102 lines (96 loc) · 3.15 KB
/
main.ts
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
function noFormat() {
let elements: Array<string> = [
"remove_comments",
"remove_lines",
"remove_report",
"check_alias",
"sign_align_in",
"sign_align_port",
"sign_align_generic",
"sign_align_function",
"sign_align_procedure",
"sign_align_all",
"new_line_after",
"use_space",
"customise_indentation",
"compress",
"mix_letter",
"cust_eol",
"sign_align_mode",
"keyword",
"typename",
"align_comments",
"add_extraEOL"
];
var isDisabled = getHTMLInputElement("no_format").checked;
changeStateOfElements(elements, isDisabled);
let radioButtons = <HTMLCollectionOf<HTMLInputElement>>document.getElementsByTagName("input");
for (let i = 0; i < radioButtons.length; i++) {
if ((<HTMLInputElement>radioButtons[i]).type == "radio") {
(<HTMLInputElement>radioButtons[i]).disabled = isDisabled;
}
}
}
function changeStateOfElements(elements: string[], isDisabled: boolean) {
elements.forEach(element => {
var htmlElement = getHTMLInputElement(element + "_div");
try {
getHTMLInputElement(element).disabled = isDisabled;
}
catch { }
if (isDisabled) {
htmlElement.className += " disabled";
}
else {
htmlElement.className = htmlElement.className.replace(/\bdisabled\b/g, "");
}
});
}
function getHTMLInputElement(id: string): HTMLInputElement {
return <HTMLInputElement>document.getElementById(id);
}
function Compress(input: string) {
input = input.replace(/\r\n/g, '');
input = input.replace(/[\t ]+/g, ' ');
input = input.replace(/[ ]?([&=:\-<>\+|])[ ]?/g, '$1');
return input;
}
function MixLetters(input: string) {
let arr = input.split("");
for (var k = 0; k < arr.length; k++) {
if (arr[k] === arr[k].toUpperCase() && Math.random() > 0.5) {
arr[k] = arr[k].toLowerCase();
} else if (Math.random() > 0.5) {
arr[k] = arr[k].toUpperCase();
}
}
return arr.join("");
}
function wordWrap() {
let d = getHTMLInputElement("result");
if (d.className == "") {
d.className = "wordwrap";
} else {
d.className = "";
}
}
function alignAllSigns(alignAll: boolean) {
if (alignAll) {
getHTMLInputElement("sign_align_port").checked = false;
getHTMLInputElement("sign_align_generic").checked = false;
getHTMLInputElement("sign_align_procedure").checked = false;
getHTMLInputElement("sign_align_function").checked = false;
getHTMLInputElement("sign_align_mode_div").disabled = false;
}
else {
getHTMLInputElement("sign_align_all").checked = false;
}
let isDisabled = !alignAll;
changeStateOfElements(["sign_align_mode"], isDisabled);
let radioButtons = document.querySelectorAll("#sign_align_mode_div input[type=radio]");
for (let i = 0; i < radioButtons.length; i++) {
if ((<HTMLInputElement>radioButtons[i]).type == "radio") {
(<HTMLInputElement>radioButtons[i]).disabled = isDisabled;
}
}
}