diff --git a/components/status-dropdown/dropdown-manager.ts b/components/status-dropdown/dropdown-manager.ts index e34b400..b72a896 100644 --- a/components/status-dropdown/dropdown-manager.ts +++ b/components/status-dropdown/dropdown-manager.ts @@ -1,4 +1,4 @@ -import { MarkdownView, Editor, Notice, TFile } from 'obsidian'; +import { MarkdownView, Editor, Notice, TFile, App } from 'obsidian'; import { DropdownUI } from './dropdown-ui'; import { DropdownOptions, DropdownDependencies } from './types'; import { createDummyTarget } from './dropdown-position'; @@ -9,12 +9,15 @@ import { NoteStatusSettings } from 'models/types'; * High-level manager for status dropdown interactions */ export class DropdownManager { - private app: any; + private app: App; private settings: NoteStatusSettings; private statusService: StatusService; private currentStatuses: string[] = ['unknown']; private toolbarButton?: HTMLElement; - private dropdownUI: DropdownUI; + private dropdownUI: DropdownUI; + + // Singleton para gestionar todos los dropdowns + private static activeInstance: DropdownManager | null = null; constructor(app: any, settings: NoteStatusSettings, statusService: StatusService) { this.app = app; @@ -35,7 +38,6 @@ export class DropdownManager { this.dropdownUI.setOnStatusChange((statuses) => { this.currentStatuses = [...statuses]; this.updateToolbarButton(); - // this.statusService.notifyStatusChanged(statuses); }); this.dropdownUI.setOnRemoveStatusHandler(async (status, targetFile) => { @@ -99,6 +101,7 @@ export class DropdownManager { private updateToolbarButton(): void { if (!this.toolbarButton) return; + DropdownManager.activeInstance?.dropdownUI.close(); this.toolbarButton.empty(); const hasValidStatus = this.currentStatuses.length > 0 && @@ -158,7 +161,8 @@ export class DropdownManager { /** * Updates the dropdown UI based on current statuses */ - public update(currentStatuses: string[] | string): void { + public update(currentStatuses: string[] | string, file?: TFile): void { + this.currentStatuses = Array.isArray(currentStatuses) ? [...currentStatuses] : [currentStatuses]; @@ -240,18 +244,14 @@ export class DropdownManager { * Universal function to open the status dropdown */ public openStatusDropdown(options: DropdownOptions): void { - if (this.dropdownUI.isOpen) { - this.dropdownUI.close(); - setTimeout(() => this._openStatusDropdown(options), 50); - } else { - this._openStatusDropdown(options); + // Cerrar dropdown activo antes de abrir uno nuevo + if (DropdownManager.activeInstance && DropdownManager.activeInstance !== this) { + console.log("close this:, ",DropdownManager.activeInstance) + this.resetDropdownState(); + DropdownManager.activeInstance.dropdownUI.close(); } - } + DropdownManager.activeInstance = this; - /** - * Internal method to open dropdown - */ - private _openStatusDropdown(options: DropdownOptions): void { const files = options.files || [this.app.workspace.getActiveFile()].filter(Boolean); if (!files.length) { new Notice('No files selected'); @@ -277,6 +277,7 @@ export class DropdownManager { this.positionAndOpenDropdown(options); } + /** * Reset dropdown state before opening diff --git a/components/status-dropdown/dropdown-ui.ts b/components/status-dropdown/dropdown-ui.ts index b44c95a..8c06e63 100644 --- a/components/status-dropdown/dropdown-ui.ts +++ b/components/status-dropdown/dropdown-ui.ts @@ -184,12 +184,10 @@ export class DropdownUI { this.isOpen = false; - setTimeout(() => { - if (this.dropdownElement) { - this.dropdownElement.remove(); - this.dropdownElement = null; - } - }, this.animationDuration); + if (this.dropdownElement) { + this.dropdownElement.remove(); + this.dropdownElement = null; + } } /** diff --git a/integrations/workspace/workspace-integration.ts b/integrations/workspace/workspace-integration.ts index a26a5ad..96a2c71 100644 --- a/integrations/workspace/workspace-integration.ts +++ b/integrations/workspace/workspace-integration.ts @@ -62,7 +62,7 @@ export class WorkspaceIntegration { this.toolbarIntegration.addToolbarButtonToActiveLeaf(); // Actualiza estado - this.propagateNoteStatusChange(); + this.propagateNoteStatusChange(file); } /** @@ -91,7 +91,7 @@ export class WorkspaceIntegration { /** * Verifica y propaga el estado de la nota activa */ - private propagateNoteStatusChange(): void { + private propagateNoteStatusChange(file: TFile): void { try { const activeFile = this.app.workspace.getActiveFile(); let fileStatuses: string[] = []; @@ -100,7 +100,7 @@ export class WorkspaceIntegration { } // Dispara evento para que otros componentes se actualicen window.dispatchEvent(new CustomEvent('note-status:status-changed', { - detail: { statuses: fileStatuses } + detail: { statuses: fileStatuses, file: file } })); } catch (error) { console.error('Error checking note status:', error);