-
Notifications
You must be signed in to change notification settings - Fork 1
/
tagList.js
181 lines (127 loc) · 5.2 KB
/
tagList.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
// Define DEBUG features
var devTools = false;
var isPaused = false; // Stop timer. In console, type : isPaused = true
// ---------
// INIT
// ---------
var gui = require("nw.gui"); // TODO : don't know if this will be needed
var os = require('os');
var fs = require('fs');
const pathsep = require('path').sep; // Os-dependent path separator
const simpleGit = opener.simpleGit;
var state = global.state; // internal copy of global.state
var localState = global.localState;
var win
const delayInMs = 1000;
// Initiate GUI update loop
//var timer = _loopTimer( 1000);
// Storage of paths to backup files
//const backupExtension = '.orig';
var origFiles = []; // Store files found to be conflicting. Use to remove .orig files of these at the end
// ---------
// FUNCTIONS
// ---------
async function injectIntoJs(document) {
console.log('tagList.js entered');
win = gui.Window.get();
// For systems that have multiple workspaces (virtual screens)
if ( win.canSetVisibleOnAllWorkspaces() ){
win.setVisibleOnAllWorkspaces( state.onAllWorkspaces );
}
if (devTools == true){
win.showDevTools(); // WARNING : causes redraw issues on startup
}
// Set size to match content
let padding = Number(document.getElementById('outerContent').style.padding.replace('px','') );
let dx = document.getElementById('outerContent').scrollWidth * global.state.zoom;
let dy = document.getElementById('outerContent').scrollHeight * global.state.zoom;
let hx = window.outerWidth - window.innerWidth;
let hy = window.outerHeight - window.innerHeight;
window.resizeTo(dx + hx + 2 * padding , dy + hy + 2 * padding + 32);
// Always on top
win.setAlwaysOnTop( state.alwaysOnTop );
// For systems that have multiple workspaces (virtual screens)
if ( win.canSetVisibleOnAllWorkspaces() ){
win.setVisibleOnAllWorkspaces( state.onAllWorkspaces );
}
// Populate window
fillSelectWithValues(localState.arrayTagList, '*');
// Set button name
document.getElementById('Select-button').innerHTML = localState.tagListButton;
// Set title window_menu_handles_mapping
tagDialogType = localState.tagListButton;
document.title = 'Select tag to ' + tagDialogType;
};
function fillSelectWithValues( tagValues, filterRule){
let selectBox = document.getElementById("tagSelection");
selectBox.innerHTML = "";
for (let tag of tagValues) {
if ( matchRuleExpl(tag, filterRule) ){
let selectOption = document.createElement('option');
selectOption.innerHTML=tag;
selectOption.value=tag;
selectBox.appendChild(selectOption);
}
}
}
function matchRuleExpl(str, rule) {
// From : https://stackoverflow.com/questions/26246601/wildcard-string-comparison-in-javascript
// for this solution to work on any string, no matter what characters it has
var escapeRegex = (str) => str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
// "." => Find a single character, except newline or line terminator
// ".*" => Matches any string that contains zero or more characters
rule = rule.split("*").map(escapeRegex).join(".*");
// "^" => Matches any string with the following at the beginning of it
// "$" => Matches any string with that in front at the end of it
rule = "^" + rule + "$"
//Create a regular expression object for matching string
var regex = new RegExp(rule);
//Returns true if it finds a match, otherwise it returns false
return regex.test(str);
}
async function _callback( name, event, event2){
console.log('_callback = ' + name);
switch(name) {
case 'onFilterKeyUp': {
let filterRule = document.getElementById('tagFilterText').value;
filterRule = filterRule + '*'; // Implicit end with wildcard
fillSelectWithValues( localState.arrayTagList, filterRule)
break;
}
case 'Select-button' : {
console.log(event);
opener._callback('tagSelected',event); // Calling _callback in opening window
closeWindow();
break;
}
case 'Cancel-button' : {
closeWindow();
break;
}
} // End switch
// ---------------
// LOCAL FUNCTIONS
// ---------------
function makeListOfUnstagedFiles(){
let unStaged = [];
var table = document.getElementById("listFilesTableBody");
for (var i = 0, row; row = table.rows[i]; i++) {
//iterate through rows
//rows would be accessed using the "row" variable assigned in the for loop
let col = row.cells[0]; // First column
let isChecked = col.children[0].checked;
let file = col.children[1].innerText;
if (isChecked == false) {
unStaged.push(file);
}
console.log(col);
}
return unStaged;
};
// ================= END CALLBACK =================
}
function closeWindow(){
// Return
localState.tagListWindow = false; // Show to main program that window is closed
win.close();
}