Files
esengine/packages/editor-app/src/services/TauriDialogService.ts
YHH 3fb6f919f8 Feature/tilemap editor (#237)
* feat: 添加 Tilemap 编辑器插件和组件生命周期支持

* feat(editor-core): 添加声明式插件注册 API

* feat(editor-core): 改进tiledmap结构合并tileset进tiledmapeditor

* feat: 添加 editor-runtime SDK 和插件系统改进

* fix(ci): 修复SceneResourceManager里变量未使用问题
2025-11-25 22:23:19 +08:00

91 lines
2.9 KiB
TypeScript

import { singleton } from 'tsyringe';
import { open, save } from '@tauri-apps/plugin-dialog';
import type { IDialog, OpenDialogOptions, SaveDialogOptions } from '@esengine/editor-core';
export interface ConfirmDialogData {
title: string;
message: string;
confirmText: string;
cancelText: string;
onConfirm: () => void;
onCancel?: () => void;
}
export interface IDialogExtended extends IDialog {
setConfirmCallback(callback: (data: ConfirmDialogData) => void): void;
setLocale(locale: string): void;
}
@singleton()
export class TauriDialogService implements IDialogExtended {
private showConfirmCallback?: (data: ConfirmDialogData) => void;
private locale: string = 'zh';
dispose(): void {
this.showConfirmCallback = undefined;
}
setConfirmCallback(callback: (data: ConfirmDialogData) => void): void {
this.showConfirmCallback = callback;
}
setLocale(locale: string): void {
this.locale = locale;
}
async openDialog(options: OpenDialogOptions): Promise<string | string[] | null> {
const result = await open({
multiple: options.multiple || false,
directory: options.directory || false,
filters: options.filters,
defaultPath: options.defaultPath,
title: options.title
});
return result;
}
async saveDialog(options: SaveDialogOptions): Promise<string | null> {
const result = await save({
filters: options.filters,
defaultPath: options.defaultPath,
title: options.title
});
return result;
}
async showMessage(title: string, messageText: string, type: 'info' | 'warning' | 'error' = 'info'): Promise<void> {
console.warn('[TauriDialogService] showMessage not implemented with custom UI, use notification instead');
}
async showConfirm(title: string, messageText: string): Promise<boolean> {
return new Promise((resolve) => {
if (this.showConfirmCallback) {
let resolved = false;
const handleResolve = (result: boolean) => {
if (!resolved) {
resolved = true;
resolve(result);
}
};
const confirmText = this.locale === 'zh' ? '确定' : 'Confirm';
const cancelText = this.locale === 'zh' ? '取消' : 'Cancel';
this.showConfirmCallback({
title,
message: messageText,
confirmText,
cancelText,
onConfirm: () => handleResolve(true),
onCancel: () => handleResolve(false)
});
} else {
console.warn('[TauriDialogService] showConfirmCallback not set');
resolve(false);
}
});
}
}