mirror of
https://github.com/sean2077/obsidian-dynamic-theme-background.git
synced 2026-07-22 16:40:29 +00:00
feat: Add confirmation modal for clearing time rules
This commit is contained in:
parent
de6354f102
commit
dd4d3ef951
5 changed files with 74 additions and 5 deletions
|
|
@ -63,6 +63,7 @@ export default {
|
|||
end_time_label: "End Time (HH:MM):",
|
||||
interval_name: "Switch Interval",
|
||||
interval_desc: "How often to switch the background (in minutes).",
|
||||
confirm_clear_time_rules: "Are you sure you want to clear all time slot rules?",
|
||||
|
||||
// ===== 背景管理 =====
|
||||
bg_management_title: "Background Management",
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ export default {
|
|||
end_time_label: "结束时间(HH:MM):",
|
||||
interval_name: "切换间隔",
|
||||
interval_desc: "背景切换的间隔时间(分钟)",
|
||||
confirm_clear_time_rules: "您确定要清除所有时段规则吗?",
|
||||
|
||||
// ===== 背景管理 =====
|
||||
bg_management_title: "背景管理",
|
||||
|
|
|
|||
55
src/modals/confirm-modal.ts
Normal file
55
src/modals/confirm-modal.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { App, Modal, Setting } from "obsidian";
|
||||
import { t } from "../i18n";
|
||||
|
||||
export class ConfirmModal extends Modal {
|
||||
message: string;
|
||||
confirmText: string;
|
||||
cancelText: string;
|
||||
onConfirm: () => void;
|
||||
onCancel?: () => void;
|
||||
|
||||
constructor(
|
||||
app: App,
|
||||
options: {
|
||||
message: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
onConfirm: () => void;
|
||||
onCancel?: () => void;
|
||||
}
|
||||
) {
|
||||
super(app);
|
||||
this.message = options.message;
|
||||
this.confirmText = options.confirmText ?? t("button_confirm");
|
||||
this.cancelText = options.cancelText ?? t("button_cancel");
|
||||
this.onConfirm = options.onConfirm;
|
||||
this.onCancel = options.onCancel;
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
contentEl.createDiv({ text: this.message, cls: "dtb-confirm-modal-message" });
|
||||
const buttonContainer = contentEl.createDiv({ cls: "dtb-confirm-modal-buttons" });
|
||||
|
||||
new Setting(buttonContainer)
|
||||
.addButton((btn) => {
|
||||
btn.setButtonText(this.confirmText)
|
||||
.setCta()
|
||||
.onClick(() => {
|
||||
this.close();
|
||||
this.onConfirm();
|
||||
});
|
||||
})
|
||||
.addButton((btn) => {
|
||||
btn.setButtonText(this.cancelText).onClick(() => {
|
||||
this.close();
|
||||
this.onCancel?.();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onClose() {
|
||||
this.contentEl.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
*/
|
||||
|
||||
export { BackgroundModal } from "./background-modal";
|
||||
export { ConfirmModal } from "./confirm-modal";
|
||||
export { ImageFolderSuggestModal } from "./image-folder-suggest-modal";
|
||||
export { ImagePathSuggestModal } from "./image-path-suggest-modal";
|
||||
export { TimeRuleModal } from "./time-rule-modal";
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@
|
|||
import { App, Notice, PluginSettingTab, Setting, TFile } from "obsidian";
|
||||
import { getDefaultSettings } from "../default-settings";
|
||||
import { t } from "../i18n";
|
||||
import { BackgroundModal, ImageFolderSuggestModal, TimeRuleModal, WallpaperApiEditorModal } from "../modals";
|
||||
import {
|
||||
BackgroundModal,
|
||||
ConfirmModal,
|
||||
ImageFolderSuggestModal,
|
||||
TimeRuleModal,
|
||||
WallpaperApiEditorModal,
|
||||
} from "../modals";
|
||||
import type DynamicThemeBackgroundPlugin from "../plugin";
|
||||
import type { BackgroundItem, DTBSettings, TimeRule } from "../types";
|
||||
import { DragSort, addDropdownOptionHoverTooltip, addDropdownTooltip, addEnhancedDropdownTooltip } from "../utils";
|
||||
|
|
@ -333,10 +339,15 @@ export class DTBSettingTab extends PluginSettingTab {
|
|||
button.setButtonText(t("clear_time_rules_button"));
|
||||
button.setTooltip(t("clear_time_rules_tooltip"));
|
||||
button.onClick(async () => {
|
||||
this.plugin.settings.timeRules = [];
|
||||
this.plugin.startBackgroundManager(); // 重新启动背景管理器以应用更改
|
||||
await this.plugin.saveSettings();
|
||||
this.displayBasicSettings(containerEl);
|
||||
new ConfirmModal(this.app, {
|
||||
message: t("confirm_clear_time_rules"),
|
||||
onConfirm: async () => {
|
||||
this.plugin.settings.timeRules = [];
|
||||
this.plugin.startBackgroundManager(); // 重新启动背景管理器以应用更改
|
||||
await this.plugin.saveSettings();
|
||||
this.displayBasicSettings(containerEl);
|
||||
},
|
||||
}).open();
|
||||
});
|
||||
})
|
||||
.addButton((button) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue