Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复空项目仍提示保存的问题 #270

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/stage/stageManager/StageManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export namespace StageManager {
});
}

export function isEmpty(): boolean {
return entities.length === 0;
}
export function getTextNodes(): TextNode[] {
return entities.valuesToArray().filter((node) => node instanceof TextNode);
}
Expand Down
64 changes: 35 additions & 29 deletions src/pages/_app_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function AppMenu({
* 新建草稿
*/
const onNewDraft = () => {
if (StageSaveManager.isSaved()) {
if (StageSaveManager.isSaved() || StageManager.isEmpty()) {
StageManager.destroy();
setFile("Project Graph");
} else {
Expand Down Expand Up @@ -99,36 +99,42 @@ export default function AppMenu({
};

const onOpen = async () => {
if (Stage.Path.isDraft() && !StageSaveManager.isSaved()) {
Dialog.show({
title: "草稿未保存",
content: "当前草稿未保存,是否保存?",
buttons: [
{ text: "我再想想" },
{ text: "保存草稿", onClick: onSave },
{
text: "丢弃并打开新文件",
onClick: () => {
StageManager.destroy();
openFileByDialogWindow();
if (!StageSaveManager.isSaved()) {
if (StageManager.isEmpty()) {
//空项目不需要保存
StageManager.destroy();
openFileByDialogWindow();
} else if (Stage.Path.isDraft()) {
Dialog.show({
title: "草稿未保存",
content: "当前草稿未保存,是否保存?",
buttons: [
{ text: "我再想想" },
{ text: "保存草稿", onClick: onSave },
{
text: "丢弃并打开新文件",
onClick: () => {
StageManager.destroy();
openFileByDialogWindow();
},
},
},
],
});
} else if (!StageSaveManager.isSaved()) {
Dialog.show({
title: "未保存",
content: "是否保存当前文件?",
buttons: [
{
text: "保存并打开新文件",
onClick: () => {
onSave().then(openFileByDialogWindow);
],
});
} else {
Dialog.show({
title: "未保存",
content: "是否保存当前文件?",
buttons: [
{
text: "保存并打开新文件",
onClick: () => {
onSave().then(openFileByDialogWindow);
},
},
},
{ text: "我再想想" },
],
});
{ text: "我再想想" },
],
});
}
} else {
// 直接打开文件
openFileByDialogWindow();
Expand Down
5 changes: 4 additions & 1 deletion src/pages/_start_file_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Switch from "../components/ui/Switch";
import { RecentFileManager } from "../core/service/RecentFileManager";
import { StartFilesManager } from "../core/service/StartFilesManager";
import { StageSaveManager } from "../core/stage/StageSaveManager";
import { StageManager } from "../core/stage/stageManager/StageManager";
import { fileAtom } from "../state";
import { cn } from "../utils/cn";
import { Dialog } from "../utils/dialog";
Expand Down Expand Up @@ -123,7 +124,9 @@ export default function StartFilePanel({ open = false }: { open: boolean }) {
};
const onLoadCurrentStartFile = (path: string) => {
return function () {
if (currentFile === "Project Graph") {
if (StageManager.isEmpty()) {
checkoutFile(path);
} else if (currentFile === "Project Graph") {
Dialog.show({
title: "真的要切换吗?",
content: "您现在的新建草稿没有保存,是否要切换项目?",
Expand Down