diff --git a/src/Add-on/Open.ts b/src/Add-on/Open.ts index a720c48d9..fe37ab880 100644 --- a/src/Add-on/Open.ts +++ b/src/Add-on/Open.ts @@ -1,3 +1,4 @@ +import { StoreageKeys } from "../Common/StoreageKeys"; import { FileServer } from "../DatabaseServices/FileServer"; import { Command } from "../Editor/CommandMachine"; @@ -5,7 +6,7 @@ export class Open implements Command { async exec() { - let fid = localStorage.getItem('lastfid'); + let fid = localStorage.getItem(StoreageKeys.LastOpenFileId); if (fid) (FileServer.GetInstance() as FileServer).OpenFile(fid); } diff --git a/src/Add-on/ReOpen.ts b/src/Add-on/ReOpen.ts new file mode 100644 index 000000000..403792ac6 --- /dev/null +++ b/src/Add-on/ReOpen.ts @@ -0,0 +1,32 @@ +import { Command } from "../Editor/CommandMachine"; +import { FileServer } from "../DatabaseServices/FileServer"; +import { app } from "../ApplicationServices/Application"; +import { IsDev } from "../Common/Deving"; +export class ReOpen implements Command +{ + async exec() + { + if (!IsDev() && !app.Saved) + { + let res = await app.Editor.GetKeyWords({ + Msg: "当前图纸未保存,是否放弃当前图纸继续新建?", + KeyWordList: [ + { key: "Y", msg: "是" }, + { key: "N", msg: "否" }, + ], + Default: "N" + }); + if (res.StringResult !== "Y") + return; + } + + let fileServer = FileServer.GetInstance() as FileServer; + if (fileServer.m_CurFileId) + { + let id = fileServer.m_CurFileId; + app.CreateDocument(); + fileServer.m_CurFileId = undefined; + fileServer.OpenFile(id); + } + } +} diff --git a/src/Add-on/Save.ts b/src/Add-on/Save.ts index ab53ccd9e..98a865d7a 100644 --- a/src/Add-on/Save.ts +++ b/src/Add-on/Save.ts @@ -3,6 +3,7 @@ import { app } from '../ApplicationServices/Application'; import { FileSystem } from '../Common/FileSystem'; import { RequestStatus, uploadLogo } from '../Common/Request'; import { deflate, GetCurrentViewPreViewImage } from '../Common/SerializeMaterial'; +import { StoreageKeys } from "../Common/StoreageKeys"; import { FileServer } from '../DatabaseServices/FileServer'; import { Command } from '../Editor/CommandMachine'; @@ -34,6 +35,7 @@ export class Save implements Command if (data.err_code === RequestStatus.Ok) { fileServer.m_CurFileId = data.files.file_id; + localStorage.setItem(StoreageKeys.LastOpenFileId, fileServer.m_CurFileId); } } diff --git a/src/Common/StoreageKeys.ts b/src/Common/StoreageKeys.ts index a6d7ecbe5..4439bd228 100644 --- a/src/Common/StoreageKeys.ts +++ b/src/Common/StoreageKeys.ts @@ -8,4 +8,5 @@ export enum StoreageKeys ConfigName = "configName_", IsNewErp = "isNewErp", RoomName = "roomName", + LastOpenFileId = "lastfid", } diff --git a/src/DatabaseServices/FileServer.ts b/src/DatabaseServices/FileServer.ts index daa42d474..9d7cd7e46 100644 --- a/src/DatabaseServices/FileServer.ts +++ b/src/DatabaseServices/FileServer.ts @@ -5,6 +5,7 @@ import { FileUrls } from "../Common/HostUrl"; import { DirectoryId, PostJson, RequestStatus } from "../Common/Request"; import { inflate } from "../Common/SerializeMaterial"; import { Singleton } from "../Common/Singleton"; +import { StoreageKeys } from "../Common/StoreageKeys"; import { IDirectoryProps } from "../UI/Components/SourceManage/CommonPanel"; import { CADFiler } from "./CADFiler"; @@ -148,6 +149,6 @@ export class FileServer extends Singleton { if (fileInfo.name) this.currentFileInfo.name = fileInfo.name; - localStorage.setItem('lastfid', fileInfo.file_id || ""); + localStorage.setItem(StoreageKeys.LastOpenFileId, fileInfo.file_id || ""); } } diff --git a/src/Editor/CommandRegister.ts b/src/Editor/CommandRegister.ts index c28cf9922..d20ddb3b9 100644 --- a/src/Editor/CommandRegister.ts +++ b/src/Editor/CommandRegister.ts @@ -99,6 +99,7 @@ import { PasteClip } from "../Add-on/PasteClip"; import { Pedit } from "../Add-on/Pedit"; import { Command_PLTest } from "../Add-on/polytest"; import { Command_Purge } from "../Add-on/Purge"; +import { ReOpen } from "../Add-on/ReOpen"; import { Command_RestoreColor } from "../Add-on/RestoreColor"; import { Command_Reverse } from "../Add-on/Reverse"; import { Command_Rotate } from "../Add-on/Rotate"; @@ -207,6 +208,7 @@ export function registerCommand() commandMachine.RegisterCommand("new", new New()); commandMachine.RegisterCommand("open", new Open()); + commandMachine.RegisterCommand("reopen", new ReOpen()); commandMachine.RegisterCommand("arc", new DrawArc()); diff --git a/src/UI/Components/MainContent/Content.tsx b/src/UI/Components/MainContent/Content.tsx index 173ce66ea..55b52148b 100644 --- a/src/UI/Components/MainContent/Content.tsx +++ b/src/UI/Components/MainContent/Content.tsx @@ -4,6 +4,7 @@ import { inject, observer } from 'mobx-react'; import * as React from 'react'; import { IsDev } from '../../../Common/Deving'; import { CURRENT_HOST, ResourcesCDN_HOST } from '../../../Common/HostUrl'; +import { StoreageKeys } from '../../../Common/StoreageKeys'; import { FileServer } from '../../../DatabaseServices/FileServer'; import { TopPanelStore } from '../../Store/TopPanelStore'; import { Carousel } from '../Carousel'; @@ -33,7 +34,7 @@ export class ContentComponent extends React.Component<{ store?: TopPanelStore; } { this.props.store.openMain = false; this.props.store.editoring = true; - let fid = localStorage.getItem('lastfid'); + let fid = localStorage.getItem(StoreageKeys.LastOpenFileId); if (fid) (FileServer.GetInstance() as FileServer).OpenFile(fid); return; diff --git a/src/UI/Components/SourceManage/FilePanel.tsx b/src/UI/Components/SourceManage/FilePanel.tsx index 24794588d..fe5d6653f 100644 --- a/src/UI/Components/SourceManage/FilePanel.tsx +++ b/src/UI/Components/SourceManage/FilePanel.tsx @@ -4,9 +4,10 @@ import { inject, observer } from 'mobx-react'; import * as React from 'react'; import { app } from '../../../ApplicationServices/Application'; import { FileSystem } from '../../../Common/FileSystem'; -import { FileUrls, CURRENT_HOST } from '../../../Common/HostUrl'; +import { CURRENT_HOST, FileUrls } from '../../../Common/HostUrl'; import { DirectoryId } from '../../../Common/Request'; import { deflate } from '../../../Common/SerializeMaterial'; +import { StoreageKeys } from '../../../Common/StoreageKeys'; import { FileFormatReg } from '../../../Common/Utils'; import { FileServer } from '../../../DatabaseServices/FileServer'; import { TopPanelStore } from '../../Store/TopPanelStore'; @@ -127,9 +128,9 @@ export class FilePanel extends React.Component<{ store?: TopPanelStore; }, {}> let server = FileServer.GetInstance() as FileServer; if (data.file_ids.includes(server.m_CurFileId)) this.handleAddNewFile("新文件", this.commonPanel['currentDir']); - let lastFid = localStorage.getItem('lastfid'); - if (data.file_ids.includes(lastFid)) - localStorage.setItem('lastfid', ""); + let lastFileId = localStorage.getItem(StoreageKeys.LastOpenFileId); + if (data.file_ids.includes(lastFileId)) + localStorage.setItem(StoreageKeys.LastOpenFileId, ""); }; renderNav = () => {