Skip to content

Commit 91bdc84

Browse files
committed
ui overhaul and added custom chokidar support
1 parent b93a126 commit 91bdc84

14 files changed

+511
-171
lines changed

SourceCode/public/importer.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// console.log(document.querySelector('link').import.querySelector('link'))
2020
</script>
2121
<script src="modules/modules.js"></script>
22+
<script src="modules/xp_chokidar.js"></script>
2223
<script src="modules/explorer.js"></script>
2324
<script src="modules/icon.js"></script>
2425
<script src="modules/settingsManager.js"></script>
27.5 KB
Binary file not shown.

SourceCode/public/modules/explorer.js

Lines changed: 125 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ window.sidebarTabs = {
33
}
44

55
const treeChangeEvent = (directoryEl, create) => {
6-
let directoriesInPath = directoryEl.full_path.split('\\').length;
6+
let parentDir = path.dirname(directoryEl.full_path);
7+
let directoriesInPath = parentDir.split('\\').length;
78
let directoriesInLaunchPath = launchArguments.split('\\').length;
89
let level = directoriesInPath - directoriesInLaunchPath;
9-
let parentDir = path.dirname(directoryEl.full_path);
1010
let index = directoryEl.index || file_explorer.folders[parentDir].children.findIndex(child => child.full_path === directoryEl.full_path);
1111

1212
// ${level}_${parentDir}
@@ -15,7 +15,8 @@ const treeChangeEvent = (directoryEl, create) => {
1515
element: directoryEl,
1616
parentDir,
1717
index,
18-
create
18+
create,
19+
level
1920
}
2021
})
2122
}
@@ -155,14 +156,15 @@ window.file_explorer = {
155156

156157
if(file_explorer.folders[parentDir]) {
157158
if(new Date() - file_explorer.folders[parentDir].last_sorted >= 500) {
158-
file_explorer.folders[parentDir].children = file_explorer.sortDirectories([...file_explorer.folders[parentDir].children, details]);
159+
file_explorer.folders[parentDir].children = file_explorer.sortDirectories([...(file_explorer.folders[parentDir]).children, details]);
159160
last_sorted = new Date();
160161
} else {
161-
file_explorer.folders[parentDir].children = [...file_explorer.folders[parentDir].children, details];
162+
file_explorer.folders[parentDir].children = [...(file_explorer.folders[parentDir]).children, details];
162163
}
163164
}
164165
} else {
165166
if(isFolder) {
167+
console.log('FOLDER GOT DELETED', filePath);
166168
file_explorer.folders[filePath] = undefined;
167169
}
168170

@@ -183,17 +185,126 @@ window.file_explorer = {
183185
}
184186
// file_explorer.folders
185187
},
188+
explorerItemMenuConfig: (full_path) => [
189+
{
190+
label: 'Open Preview',
191+
name: 'open_preview',
192+
custom: (filePath) => {
193+
let fileBasename = path.basename(filePath);
194+
let isAMarkdownFile = fileBasename.includes('.md');
195+
196+
let canPreview = isAMarkdownFile;
197+
198+
return canPreview;
199+
}
200+
},
201+
{
202+
label: "Run Code",
203+
name: "run_code"
204+
},
205+
{
206+
label: "Open to the Side",
207+
name: "open_to_the_side"
208+
},
209+
{
210+
label: "Open With...",
211+
name: "open_with"
212+
},
213+
{
214+
label: "Reveal in File Explorer",
215+
name: "reveal_in_file_explorer"
216+
},
217+
{
218+
label: "Open in Integrated Terminal",
219+
name: "open_in_integrated_terminal"
220+
},
221+
{
222+
separator: true
223+
},
224+
{
225+
label: "Select for Compare",
226+
name: "select_for_compare"
227+
},
228+
{
229+
label: "Find File References",
230+
name: "find_file_references"
231+
},
232+
{
233+
label: "Open Timeline",
234+
name: "open_timeline"
235+
},
236+
{
237+
separator: true
238+
},
239+
{
240+
label: "Cut",
241+
name: "cut"
242+
},
243+
{
244+
label: "Copy",
245+
name: "copy"
246+
},
247+
{
248+
separator: true
249+
},
250+
{
251+
label: "Copy Path",
252+
name: "copy_path",
253+
click: () => {
254+
fsUtils.copyToClipboard(full_path);
255+
}
256+
},
257+
{
258+
label: "Copy Relative Path",
259+
name: "copy_relative_path",
260+
click: () => {
261+
fsUtils.copyToClipboard(path.relative(launchArguments, full_path));
262+
}
263+
},
264+
{
265+
separator: true
266+
},
267+
{
268+
label: "Rename...",
269+
name: "rename",
270+
click: () => {
271+
isStaging = !isStaging;
272+
}
273+
},
274+
{
275+
label: "Delete",
276+
name: "delete", //
277+
click: () => {
278+
console.log('Deleting');
279+
280+
if(isFolder) {
281+
fs.rmdirSync(full_path);
282+
} else {
283+
fs.unlinkSync(full_path);
284+
}
285+
286+
// file_explorer.rescan();
287+
}
288+
}
289+
]
186290
};
187291

188-
const watcher = chokidar.watch(launchArguments, {
189-
ignored: /(^|[\/\\])\../, // ignore dotfiles
190-
persistent: true
191-
});
292+
// const watcher = chokidar.watch(launchArguments, {
293+
// ignored: /(^|[\/\\])\../, // ignore dotfiles
294+
// persistent: true
295+
// });
296+
192297

193-
watcher.on('addDir', path => file_explorer.chokidarUpdate(path, true, true));
194-
watcher.on('unlinkDir', path => file_explorer.chokidarUpdate(path, true, false));
298+
xp_chokidar.on('Directory created', path => file_explorer.chokidarUpdate(path, true, true))
299+
xp_chokidar.on('Directory deleted', path => file_explorer.chokidarUpdate(path, true, false));
300+
// watcher.on('addDir', path => file_explorer.chokidarUpdate(path, true, true));
301+
// watcher.on('unlinkDir', path => file_explorer.chokidarUpdate(path, true, false));
195302

196-
watcher.on('add', path => file_explorer.chokidarUpdate(path, false, true));
197-
watcher.on('unlink', path => file_explorer.chokidarUpdate(path, false, false));
303+
xp_chokidar.on('File created', path => file_explorer.chokidarUpdate(path, false, true));
304+
xp_chokidar.on('File deleted', path => file_explorer.chokidarUpdate(path, false, false));
305+
// watcher.on('add', path => file_explorer.chokidarUpdate(path, false, true));
306+
// watcher.on('unlink', path => file_explorer.chokidarUpdate(path, false, false));
198307

199-
watcher.on('change', path => console.log(`File ${path} has been changed`));
308+
xp_chokidar.on('File modified', path => console.log(`File ${path} has been changed`));
309+
xp_chokidar.watch(launchArguments)
310+
// watcher.on('change', path => console.log(`File ${path} has been changed`));

SourceCode/public/modules/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ window.utils = {
1313
}
1414
}
1515

16+
window.elementUtils = {
17+
getClassList: (element) => {
18+
if(!element.parentElement) {
19+
return [];
20+
}
21+
22+
return [...elementUtils.getClassList(element.parentElement), element.className];
23+
}
24+
}
25+
1626
window.fsUtils = {
1727
copyToClipboard: (textToCopy) => {
1828
const textArea = document.createElement("textarea");
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
window.xp_chokidar = (() => {
3+
const path = require('path');
4+
const { spawn } = require('child_process');
5+
6+
let cachedWatchers = (() => {
7+
let _cases = {
8+
"File created": [],
9+
"File deleted": [],
10+
"Directory created": [],
11+
"Directory deleted": [],
12+
"File modified": []
13+
};
14+
15+
let _on = (/**@type {chokidarCases} */ chokidarCase, cb) => {
16+
(_cases[chokidarCase] || []).push(cb);
17+
};
18+
19+
let chokidarEvent = (/** @type {string}*/ _event) => {
20+
let [eventCase, eventPath] = _event.split(": ");
21+
22+
let funcs = _cases[eventCase];
23+
24+
if(funcs) {
25+
funcs.forEach((subscribedFunction) => {
26+
subscribedFunction(eventPath);
27+
});
28+
}
29+
};
30+
31+
return {
32+
on: _on,
33+
unwatch: (/**@type {chokidarCases} */ chokidarCase) => {
34+
_cases[chokidarCase] = [];
35+
},
36+
event: chokidarEvent
37+
};
38+
})();
39+
40+
let chokidarPath = path.resolve('public\\modules\\chokidar\\xp_chokidar.exe');
41+
42+
let directoryWatcher = (pathToExec) => {
43+
const watcherProcess = spawn(chokidarPath, [pathToExec]);
44+
45+
watcherProcess.stdout.on('data', (data) => {
46+
const outputLines = data.toString().split('\n');
47+
48+
outputLines.forEach((line) => {
49+
cachedWatchers.event(line.trim());
50+
});
51+
});
52+
53+
watcherProcess.stderr.on('data', (data) => {
54+
console.error(`stderr: ${data.toString()}`);
55+
});
56+
57+
watcherProcess.on('close', (code) => {
58+
console.log(`Child process exited with code ${code}`);
59+
});
60+
61+
const stopWatching = () => {
62+
if (watcherProcess) {
63+
watcherProcess.kill();
64+
watcherProcess = null;
65+
console.log('Watcher process terminated.');
66+
}
67+
}
68+
69+
if (typeof window !== 'undefined') {
70+
window.addEventListener('beforeunload', stopWatching);
71+
}
72+
73+
return watcherProcess;
74+
};
75+
76+
return {
77+
on: cachedWatchers.on,
78+
watch: directoryWatcher,
79+
unwatch: cachedWatchers.unwatch
80+
};
81+
})();
82+
}

SourceCode/src/FileExplorer/Explorer.svelte

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,85 @@ import GenericExplorerTab from "./Explorer/GenericExplorerTab.svelte";
2222
timeline: ExplorerTabTimeline,
2323
'npm scripts': ExplorerTabNpmScripts
2424
}
25+
26+
let tabButtons = {
27+
active: [
28+
{
29+
icon: 'new-file',
30+
title: 'New Untitled Text File'
31+
},
32+
{
33+
icon: 'save-all',
34+
title: 'Save All'
35+
},
36+
{
37+
icon: 'close-all-editors',
38+
title: 'Close All Editors'
39+
}
40+
],
41+
folder: [
42+
{
43+
icon: 'new-file',
44+
title: 'New File...'
45+
},
46+
{
47+
icon: 'new-folder',
48+
title: 'New Folder...'
49+
},
50+
{
51+
icon: 'refresh',
52+
title: 'Refresh Explorer'
53+
},
54+
{
55+
icon: 'collapse-all',
56+
title: 'Collapse Folders in Explorer'
57+
}
58+
],
59+
outline: [
60+
{
61+
icon: 'collapse-all',
62+
title: 'Collapse All'
63+
},
64+
{
65+
icon: 'more',
66+
title: 'More Actions...'
67+
},
68+
],
69+
timeline: [
70+
{
71+
icon: 'pin',
72+
title: 'Pin The Current Timeline'
73+
},
74+
{
75+
icon: 'refresh',
76+
title: 'Refresh'
77+
},
78+
{
79+
icon: 'filter',
80+
title: 'Filter Timeline'
81+
},
82+
{
83+
icon: 'more',
84+
title: 'More Actions...'
85+
}
86+
],
87+
'npm scripts': [
88+
{
89+
icon: 'refresh',
90+
title: 'Refresh'
91+
},
92+
{
93+
icon: 'collapse-all',
94+
title: 'Collapse All'
95+
},
96+
]
97+
}
2598
</script>
2699

27100

28101
<div class="explorer-tabs {activeTab === 'files' ? '' : 'hide'}">
29102
{#each tabsToShow as singleTab}
30-
<GenericExplorerTab tabContent={contentMapping[singleTab]} tabName={singleTab}></GenericExplorerTab>
103+
<GenericExplorerTab tabContent={contentMapping[singleTab]} tabName={singleTab} tabButtons={tabButtons[singleTab]}></GenericExplorerTab>
31104
{/each}
32105
</div>
33106

0 commit comments

Comments
 (0)