diff --git a/components/SettingsUI/BehaviourSettings.tsx b/components/SettingsUI/BehaviourSettings.tsx index 65a2b8f..72528a2 100644 --- a/components/SettingsUI/BehaviourSettings.tsx +++ b/components/SettingsUI/BehaviourSettings.tsx @@ -1,7 +1,8 @@ import { PluginSettings } from "@/types/pluginSettings"; -import React from "react"; +import React, { useMemo } from "react"; import { SettingItem } from "./SettingItem"; import { FrontmatterMappingsSettings } from "./FrontmatterMappingsSettings"; +import { BaseNoteStatusService } from "@/core/noteStatusService"; export type Props = { settings: PluginSettings; @@ -9,10 +10,51 @@ export type Props = { }; export const BehaviourSettings: React.FC = ({ settings, onChange }) => { + const availableStatuses = useMemo(() => { + return BaseNoteStatusService.getAllAvailableStatuses(); + }, [ + settings.templates, + settings.customStatuses, + settings.enabledTemplates, + ]); + return (

Status tag

+ + + + = { "singleStatusStorageMode", "strictStatuses", "enableStatusOverviewPopup", + "defaultStatusForNewNotes", ], storage: [ "tagPrefix", diff --git a/main.tsx b/main.tsx index aab14ed..93165fd 100644 --- a/main.tsx +++ b/main.tsx @@ -3,7 +3,10 @@ import StatusBarIntegration from "integrations/status-bar/status-bar"; import eventBus from "core/eventBus"; import { PluginSettingIntegration } from "./integrations/settings/pluginSettings"; import settingsService from "./core/settingsService"; -import { BaseNoteStatusService } from "./core/noteStatusService"; +import { + BaseNoteStatusService, + NoteStatusService, +} from "./core/noteStatusService"; import { StatusModalIntegration } from "./integrations/modals/statusModalIntegration"; import ContextMenuIntegration from "./integrations/context-menu/contextMenuIntegration"; import { FileExplorerIntegration } from "./integrations/file-explorer/file-explorer-integration"; @@ -240,6 +243,42 @@ export default class NoteStatusPlugin extends Plugin { "main-status-popup-setting-subscriptor", ); + this.registerEvent( + this.app.vault.on("create", async (file) => { + if ( + file instanceof TFile && + file.extension === "md" && + settingsService.settings.defaultStatusForNewNotes + ) { + // Wait a bit to ensure metadata is processed or templates are applied + setTimeout(async () => { + // Ensure file still exists + if (!this.app.vault.getAbstractFileByPath(file.path)) { + return; + } + + const noteStatusService = new NoteStatusService(file); + // Populate statuses to see if it already has any + noteStatusService.populateStatuses(); + + const groupedStatuses = + noteStatusService.getStatusesByAllKeys(); + const hasStatuses = Object.values(groupedStatuses).some( + (statuses) => statuses.length > 0, + ); + + if (!hasStatuses) { + await noteStatusService.addStatus( + settingsService.settings.tagPrefix, + settingsService.settings + .defaultStatusForNewNotes as string, + ); + } + }, 500); // Increased delay to allow more time for templates + } + }), + ); + this.registerEvent( this.app.vault.on("rename", (file) => { if (file instanceof TFile) { diff --git a/types/pluginSettings.ts b/types/pluginSettings.ts index 619552e..f93e121 100644 --- a/types/pluginSettings.ts +++ b/types/pluginSettings.ts @@ -84,5 +84,6 @@ export type PluginSettings = { syncGroups: SyncGroup[]; // Selected groups of settings to synchronize enableNonMarkdownSync: boolean; // Whether to sync non-markdown statuses to a vault file nonMarkdownSyncPath: string; // Path to the non-markdown sync file + defaultStatusForNewNotes: string | null; // Default status to apply to new notes [key: string]: unknown; };