MCPcopy
hub / github.com/kimlimjustin/xplorer / OpenDir

Function OpenDir

src/Components/Open/open.ts:32–162  ·  view source on GitHub ↗
(dir: string, reveal?: boolean, forceOpen = false)

Source from the content-addressed store, hash-verified

30 * @returns {Promise<void>}
31 */
32const OpenDir = async (dir: string, reveal?: boolean, forceOpen = false): Promise<void> => {
33 await stopSearchingProcess();
34 if (isLoading() && !forceOpen) {
35 InfoLog(`Something is still loading, refusing to open dir ${dir}`);
36 return;
37 }
38 console.time(dir);
39 // Check if the user is just want to reload the current directory
40 const isReload = (await focusingPath()) === dir && !forceOpen;
41 if (!isReload) directoryInfo?.unlisten?.();
42 startLoading();
43 changePosition(dir, forceOpen);
44 const MAIN_ELEMENT = document.getElementById('workspace');
45 MAIN_ELEMENT.innerHTML = '';
46 if (MAIN_ELEMENT.classList.contains('empty-dir-notification')) MAIN_ELEMENT.classList.remove('empty-dir-notification'); // Remove class if exist
47 if (dir === 'xplorer://Home') {
48 Home();
49 UpdateInfo('number-of-files', '');
50 OpenLog(dir);
51 } else if (dir === 'xplorer://Trash') {
52 if (!platform) platform = await OS();
53 if (platform === 'darwin') {
54 MAIN_ELEMENT.classList.add('empty-dir-notification');
55 MAIN_ELEMENT.innerText = 'Xploring trash folder is not supported for macOS yet.';
56 stopLoading();
57 } else {
58 getTrashedFiles().then(async (trashedFiles) => {
59 UpdateInfo('number-of-files', `${trashedFiles.files.length} files`);
60 if (!trashedFiles.files.length) {
61 MAIN_ELEMENT.classList.add('empty-dir-notification');
62 MAIN_ELEMENT.innerText = 'This folder is empty.';
63 stopLoading();
64 } else {
65 await displayFiles(trashedFiles.files, dir, MAIN_ELEMENT);
66 stopLoading();
67 updateTheme('grid');
68 LOAD_IMAGE();
69 changeWindowTitle(getBasename(dir));
70 }
71 });
72 }
73 OpenLog(dir);
74 } else if (dir === 'xplorer://Recent') {
75 Recent();
76 UpdateInfo('number-of-files', '');
77 OpenLog(dir);
78 } else if (dir.startsWith('Search')) {
79 // Search path pattern: Search: [[search-query]] inside [[search-path]]
80 const splitBySearchKeyword = dir.split('Search: ');
81 splitBySearchKeyword.shift();
82 const query = splitBySearchKeyword.join('Search: ');
83 const splitByInsideKeyword = query.split(' inside ');
84 if (splitByInsideKeyword.length === 2) {
85 const searchQuery = splitByInsideKeyword[0].slice(2, -2);
86 const searchPath = splitByInsideKeyword[1].slice(2, -2);
87 processSearch(searchQuery, searchPath);
88 } else {
89 for (let i = 0; i < splitByInsideKeyword.length; i++) {

Callers 15

index.tsFile · 0.90
reloadFunction · 0.90
goParentDirFunction · 0.90
windowManagerFunction · 0.90
createNewTabFunction · 0.90
SwitchTabFunction · 0.90
goBackFunction · 0.90
goForwardFunction · 0.90
TabFunction · 0.90
KeyUpShortcutsHandlerFunction · 0.90
processSearchFunction · 0.90
FileMenuFunction · 0.90

Calls 15

stopSearchingProcessFunction · 0.90
isLoadingFunction · 0.90
InfoLogFunction · 0.90
startLoadingFunction · 0.90
UpdateInfoFunction · 0.90
OpenLogFunction · 0.90
stopLoadingFunction · 0.90
getTrashedFilesFunction · 0.90
updateThemeFunction · 0.90
LOAD_IMAGEFunction · 0.90
changeWindowTitleFunction · 0.90
processSearchFunction · 0.90

Tested by

no test coverage detected