-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from LonelyFellas/main
✨Feature: 选择工程文件夹
- Loading branch information
Showing
46 changed files
with
798 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,9 @@ release/ | |
.DS_Store | ||
.vite/ | ||
|
||
# monaco-editor | ||
src/renderer/public/monaco-editor | ||
|
||
# mac | ||
.DS_Store | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"iconfont" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
declare global { | ||
interface FileInfo { | ||
name: string; | ||
parentPath: string; | ||
path: string; | ||
isDir: boolean; | ||
isEmpty: boolean; | ||
isActive: boolean; | ||
id: string; | ||
files: FileInfo[]; | ||
} | ||
} | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"window": { | ||
"width": 1024, | ||
"height": 768 | ||
}, | ||
"layout": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { dialog, ipcMain } from "electron"; | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
import os from "node:os"; | ||
import { isEmptyDir } from "./utils"; | ||
import { randomUUID } from "node:crypto"; | ||
|
||
function getFileInfo(rootName = ""): FileInfo["files"] { | ||
// 查看当前根目录的文件 | ||
const filesWithType = fs.readdirSync(rootName, { withFileTypes: true }); | ||
// 判断每一个子文件是否是文件夹,如果是文件夹,则判断是否是空文件夹 | ||
const dirFiles: FileInfo[] = []; | ||
const fileFiles: FileInfo[] = []; | ||
filesWithType.forEach((file) => { | ||
const isDir = file.isDirectory(); | ||
(isDir ? dirFiles : fileFiles).push({ | ||
name: file.name, | ||
parentPath: rootName, | ||
path: path.join(rootName, file.name), | ||
isDir: isDir, | ||
isEmpty: isDir ? isEmptyDir(path.join(rootName, file.name)) : false, | ||
isActive: false, | ||
files: [], | ||
id: randomUUID() as string, | ||
}); | ||
}); | ||
// 对dirFiles进行排序 | ||
dirFiles.sort((a, b) => a.name.localeCompare(b.name)); | ||
// 对fileFiles进行排序 | ||
fileFiles.sort((a, b) => a.name.localeCompare(b.name)); | ||
return [...dirFiles, ...fileFiles]; | ||
} | ||
/** | ||
* 打开文件 | ||
*/ | ||
ipcMain.handle("open-file", () => { | ||
const root = dialog.showOpenDialogSync({ | ||
// 用户目录 | ||
defaultPath: path.join(os.homedir(), "Dev/far-editor"), | ||
// 只能选择文件夹 | ||
properties: ["openDirectory"], | ||
}); | ||
|
||
if (root && Array.isArray(root) && root.length > 0) { | ||
const files = getFileInfo(root[0]); | ||
|
||
// 获取根目录名称 | ||
const name = path.basename(root[0]); | ||
|
||
return { | ||
name, | ||
parentPath: "", | ||
path: root[0], | ||
isDir: true, | ||
isEmpty: false, | ||
isActive: true, | ||
files, | ||
id: randomUUID(), | ||
}; | ||
} | ||
return { | ||
name: "", | ||
parentPath: "", | ||
path: "", | ||
isDir: false, | ||
isEmpty: false, | ||
isActive: true, | ||
files: [] as FileInfo[], | ||
id: randomUUID(), | ||
}; | ||
}); | ||
|
||
/** | ||
* 展开或折叠文件夹 | ||
*/ | ||
ipcMain.handle("expand-or-collapse-file", (_, rootName: string) => { | ||
return getFileInfo(rootName); | ||
}); | ||
|
||
/** | ||
* 读取文件内容 | ||
*/ | ||
ipcMain.handle("read-file", (_, fileName: string) => { | ||
return fs.readFileSync(fileName, "utf-8"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Logger from "electron-log"; | ||
import fs from "node:fs"; | ||
/** | ||
* 判断一个文件夹是否为空 | ||
* @param dir 文件夹路径 | ||
* @returns 是否为空 | ||
*/ | ||
export function isEmptyDir(dir: string) { | ||
try { | ||
return fs.readdirSync(dir).length === 0; | ||
} catch (error) { | ||
Logger.error(error); | ||
return false; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { cn } from "@common"; | ||
interface IconFontProps { | ||
name: string; | ||
className?: string; | ||
size?: number; | ||
style?: React.CSSProperties; | ||
onClick?: () => void; | ||
} | ||
export default function IconFont(props: IconFontProps) { | ||
const handleClick = () => {}; | ||
return ( | ||
<svg | ||
onClick={handleClick} | ||
className={cn( | ||
"custom-icon-font text-18px", | ||
props?.className, | ||
props?.size ? `text-${props.size}px` : "" | ||
)} | ||
aria-hidden="true" | ||
style={props?.style} | ||
> | ||
<use xlinkHref={`#icon_${props.name}`}></use> | ||
</svg> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as IconFont } from "./icon-font/index"; | ||
export { default as Tabbar } from "./tabbar"; | ||
export { default as MainEmpty } from "./main-empty"; |
Oops, something went wrong.