mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 12:30:24 +00:00
chore: status bar restored
This commit is contained in:
parent
41dd6b9c3f
commit
8b066f0fc2
11 changed files with 93 additions and 133 deletions
4
components/status-bar/index.ts
Normal file
4
components/status-bar/index.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { StatusBarController } from './status-bar-controller';
|
||||
|
||||
export { StatusBarController as StatusBar};
|
||||
export default StatusBarController;
|
||||
|
|
@ -11,27 +11,14 @@ export class StatusBarController {
|
|||
private statusService: StatusService;
|
||||
private currentStatuses: string[] = ['unknown'];
|
||||
|
||||
constructor(statusBarEl: HTMLElement, settings: NoteStatusSettings, statusService: StatusService) {
|
||||
this.view = new StatusBarView(statusBarEl);
|
||||
constructor(statusBarContainer: HTMLElement, settings: NoteStatusSettings, statusService: StatusService) {
|
||||
this.view = new StatusBarView(statusBarContainer);
|
||||
this.settings = settings;
|
||||
this.statusService = statusService;
|
||||
|
||||
// Register right-click handler for force refresh
|
||||
this.setupContextMenu(statusBarEl);
|
||||
|
||||
this.update(['unknown']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up right-click context menu for force refresh
|
||||
*/
|
||||
private setupContextMenu(element: HTMLElement): void {
|
||||
element.addEventListener('contextmenu', (e) => {
|
||||
e.preventDefault();
|
||||
window.dispatchEvent(new CustomEvent('note-status:force-refresh'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status bar with new statuses
|
||||
*/
|
||||
|
|
@ -60,21 +47,21 @@ export class StatusBarController {
|
|||
this.handleAutoHide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render statuses - handles both single and multiple status cases
|
||||
*/
|
||||
private renderStatuses(statuses: string[]): void {
|
||||
const statusDetails = statuses.map(status => {
|
||||
const statusObj = this.statusService.getAllStatuses().find(s => s.name === status);
|
||||
return {
|
||||
name: status,
|
||||
icon: this.statusService.getStatusIcon(status),
|
||||
tooltipText: statusObj?.description ? `${status} - ${statusObj.description}` : status
|
||||
};
|
||||
});
|
||||
/**
|
||||
* Render statuses - handles both single and multiple status cases
|
||||
*/
|
||||
private renderStatuses(statuses: string[]): void {
|
||||
const statusDetails = statuses.map(status => {
|
||||
const statusObj = this.statusService.getAllStatuses().find(s => s.name === status);
|
||||
return {
|
||||
name: status,
|
||||
icon: this.statusService.getStatusIcon(status),
|
||||
tooltipText: statusObj?.description ? `${status} - ${statusObj.description}` : status
|
||||
};
|
||||
});
|
||||
|
||||
this.view.renderStatuses(statusDetails);
|
||||
}
|
||||
this.view.renderStatuses(statusDetails);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle auto-hide behavior
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import { DropdownManager } from './dropdown-manager';
|
||||
import { DropdownOptions } from './types';
|
||||
|
||||
// Re-export for public use
|
||||
export { DropdownManager as StatusDropdown };
|
||||
export type { DropdownOptions };
|
||||
|
||||
// Export default to maintain compatibility with existing code
|
||||
export { DropdownManager as StatusDropdown };
|
||||
export default DropdownManager;
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { App, Menu, TFile } from 'obsidian';
|
||||
import { NoteStatusSettings } from '../../models/types';
|
||||
import { StatusService } from '../../services/status-service';
|
||||
import { StatusDropdown } from '../components/status-dropdown';
|
||||
import { ExplorerIntegration } from '../integrations/explorer-integration';
|
||||
import { StatusDropdown } from 'components/status-dropdown';
|
||||
import { ExplorerIntegration } from 'integrations/explorer';
|
||||
|
||||
/**
|
||||
* Handles context menu interactions for status changes
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { App, PluginSettingTab, Setting, Notice } from 'obsidian';
|
||||
import { Status } from '../models/types';
|
||||
import { PREDEFINED_TEMPLATES } from '../constants/status-templates';
|
||||
import { Status } from '../../models/types';
|
||||
import { PREDEFINED_TEMPLATES } from '../../constants/status-templates';
|
||||
import NoteStatus from 'main';
|
||||
import { StatusService } from 'services/status-service';
|
||||
|
||||
|
|
@ -59,68 +59,51 @@ export class WorkspaceIntegration {
|
|||
*/
|
||||
private handleFileOpen(file: TFile): void {
|
||||
// Añade el botón de la barra de herramientas
|
||||
this.toolbarIntegration.addToolbarButtonToActiveLeaf();
|
||||
// this.toolbarIntegration.addToolbarButtonToActiveLeaf();
|
||||
|
||||
// Actualiza estado
|
||||
this.checkNoteStatus();
|
||||
this.propagateNoteStatusChange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Maneja cambio de hoja activa
|
||||
*/
|
||||
private handleActiveLeafChange(leaf: WorkspaceLeaf): void {
|
||||
// Añade el botón de la barra de herramientas
|
||||
this.toolbarIntegration.addToolbarButtonToActiveLeaf();
|
||||
// // Añade el botón de la barra de herramientas
|
||||
// this.toolbarIntegration.addToolbarButtonToActiveLeaf();
|
||||
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
// const activeFile = this.app.workspace.getActiveFile();
|
||||
|
||||
// Solo actualiza si el archivo realmente cambió
|
||||
if (this.lastActiveFile?.path !== activeFile?.path) {
|
||||
this.lastActiveFile = activeFile;
|
||||
this.checkNoteStatus();
|
||||
}
|
||||
// // Solo actualiza si el archivo realmente cambió
|
||||
// if (this.lastActiveFile?.path !== activeFile?.path) {
|
||||
// this.lastActiveFile = activeFile;
|
||||
// this.propagateNoteStatusChange();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Maneja cambio de layout
|
||||
* Maneja y propaga el cambio de layout
|
||||
*/
|
||||
private handleLayoutChange(): void {
|
||||
// Actualiza componentes que dependen del layout
|
||||
this.updateStatusPane();
|
||||
window.dispatchEvent(new CustomEvent('note-status:update-pane'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifica y actualiza el estado de la nota activa
|
||||
* Verifica y propaga el estado de la nota activa
|
||||
*/
|
||||
private checkNoteStatus(): void {
|
||||
private propagateNoteStatusChange(): void {
|
||||
try {
|
||||
const activeFile = this.app.workspace.getActiveFile();
|
||||
if (!activeFile || activeFile.extension !== 'md') {
|
||||
this.updateStatusComponents(['unknown']);
|
||||
return;
|
||||
let fileStatuses: string[] = [];
|
||||
if (activeFile && activeFile.extension === 'md') {
|
||||
fileStatuses = this.statusService.getFileStatuses(activeFile)
|
||||
}
|
||||
|
||||
const statuses = this.statusService.getFileStatuses(activeFile);
|
||||
this.updateStatusComponents(statuses);
|
||||
// Dispara evento para que otros componentes se actualicen
|
||||
window.dispatchEvent(new CustomEvent('note-status:status-changed', {
|
||||
detail: { statuses: fileStatuses }
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Error checking note status:', error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza componentes de estado con nuevos estados
|
||||
*/
|
||||
private updateStatusComponents(statuses: string[]): void {
|
||||
// Dispara evento para que otros componentes se actualicen
|
||||
window.dispatchEvent(new CustomEvent('note-status:status-changed', {
|
||||
detail: { statuses }
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza el panel de estado
|
||||
*/
|
||||
private updateStatusPane(): void {
|
||||
window.dispatchEvent(new CustomEvent('note-status:update-pane'));
|
||||
}
|
||||
}
|
||||
67
main.ts
67
main.ts
|
|
@ -7,12 +7,12 @@ import { StyleService } from 'services/style-service';
|
|||
// Importar integraciones
|
||||
import { ExplorerIntegration, FileMenuIntegration } from './integrations/explorer';
|
||||
import { EditorIntegration, ToolbarIntegration } from './integrations/editor';
|
||||
import { MetadataIntegration } from './integrations/metadataCache';
|
||||
import { MetadataIntegration } from './integrations/metadata-cache';
|
||||
import { WorkspaceIntegration } from './integrations/workspace';
|
||||
|
||||
// Importar componentes UI
|
||||
import { NoteStatusSettingTab } from 'settings/settings-tab';
|
||||
import { StatusBarController } from 'components/status-bar/status-bar-controller';
|
||||
import { NoteStatusSettingTab } from 'integrations/settings/settings-tab';
|
||||
import { StatusBar } from 'components/status-bar';
|
||||
|
||||
export default class NoteStatus extends Plugin {
|
||||
settings: NoteStatusSettings;
|
||||
|
|
@ -22,7 +22,7 @@ export default class NoteStatus extends Plugin {
|
|||
styleService: StyleService;
|
||||
|
||||
// Componentes UI
|
||||
statusBarController: StatusBarController;
|
||||
statusBar: StatusBar;
|
||||
|
||||
// Integraciones
|
||||
explorerIntegration: ExplorerIntegration;
|
||||
|
|
@ -35,26 +35,22 @@ export default class NoteStatus extends Plugin {
|
|||
async onload() {
|
||||
try {
|
||||
await this.loadSettings();
|
||||
|
||||
// 1. Inicializar servicios básicos
|
||||
// this.initializeServices();
|
||||
this.initializeServices();
|
||||
|
||||
// 2. Registrar vistas y componentes UI
|
||||
// this.registerViews();
|
||||
|
||||
this.initializeUI();
|
||||
|
||||
// 3. Inicializar integraciones
|
||||
// this.initializeIntegrations();
|
||||
this.initializeIntegrations();
|
||||
|
||||
// 4. Registrar comandos
|
||||
// this.registerCommands();
|
||||
|
||||
// 5. Registrar eventos personalizados
|
||||
// this.setupCustomEvents();
|
||||
this.setupCustomEvents();
|
||||
|
||||
// 6. Esperar a que el layout esté listo para inicializar UI
|
||||
// this.app.workspace.onLayoutReady(() => {
|
||||
// this.initializeUI();
|
||||
// });
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error loading Note Status plugin:', error);
|
||||
|
|
@ -67,8 +63,8 @@ export default class NoteStatus extends Plugin {
|
|||
}
|
||||
|
||||
private initializeServices() {
|
||||
// this.statusService = new StatusService(this.app, this.settings);
|
||||
// this.styleService = new StyleService(this.settings);
|
||||
this.statusService = new StatusService(this.app, this.settings);
|
||||
this.styleService = new StyleService(this.settings);
|
||||
}
|
||||
|
||||
private registerViews() {
|
||||
|
|
@ -110,18 +106,18 @@ export default class NoteStatus extends Plugin {
|
|||
// this.explorerIntegration
|
||||
// );
|
||||
|
||||
// this.workspaceIntegration = new WorkspaceIntegration(
|
||||
// this.app,
|
||||
// this.settings,
|
||||
// this.statusService,
|
||||
// this.toolbarIntegration
|
||||
// );
|
||||
this.workspaceIntegration = new WorkspaceIntegration(
|
||||
this.app,
|
||||
this.settings,
|
||||
this.statusService,
|
||||
this.toolbarIntegration
|
||||
);
|
||||
|
||||
// // 3. Registrar eventos en cada integración
|
||||
// this.fileMenuIntegration.registerFileMenus();
|
||||
// this.editorIntegration.registerEditorMenus();
|
||||
// this.metadataIntegration.registerMetadataEvents();
|
||||
// this.workspaceIntegration.registerWorkspaceEvents();
|
||||
this.workspaceIntegration.registerWorkspaceEvents();
|
||||
}
|
||||
|
||||
private registerCommands() {
|
||||
|
|
@ -164,20 +160,20 @@ export default class NoteStatus extends Plugin {
|
|||
// // Evento para cambios de configuración
|
||||
// window.addEventListener('note-status:settings-changed', this.saveSettings.bind(this));
|
||||
|
||||
// // Evento para cambios de estado
|
||||
// window.addEventListener('note-status:status-changed', this.handleStatusChanged.bind(this));
|
||||
// Evento para cambios de estado
|
||||
window.addEventListener('note-status:status-changed', this.handleStatusChanged.bind(this));
|
||||
|
||||
// // Evento para actualización de UI
|
||||
// window.addEventListener('note-status:refresh-ui', this.refreshUI.bind(this));
|
||||
}
|
||||
|
||||
private initializeUI() {
|
||||
// // Inicializar barra de estado
|
||||
// this.statusBarController = new StatusBarController(
|
||||
// this.addStatusBarItem(),
|
||||
// this.settings,
|
||||
// this.statusService
|
||||
// );
|
||||
// Inicializar barra de estado
|
||||
this.statusBar = new StatusBar(
|
||||
this.addStatusBarItem(),
|
||||
this.settings,
|
||||
this.statusService
|
||||
);
|
||||
|
||||
// // Inicializar iconos del explorador (con retraso para evitar ralentizar el inicio)
|
||||
// if (this.settings.showStatusIconsInExplorer) {
|
||||
|
|
@ -188,10 +184,11 @@ export default class NoteStatus extends Plugin {
|
|||
}
|
||||
|
||||
private handleStatusChanged(event: CustomEvent) {
|
||||
// const { statuses, file } = event.detail;
|
||||
const { statuses, file } = event.detail;
|
||||
|
||||
// // Actualizar barra de estado
|
||||
// this.statusBarController.update(statuses);
|
||||
console.log("Note status changed", statuses)
|
||||
// Actualizar barra de estado
|
||||
this.statusBar.update(statuses);
|
||||
|
||||
// // Actualizar toolbar
|
||||
// this.toolbarIntegration.updateStatusDisplay(statuses);
|
||||
|
|
@ -268,7 +265,7 @@ export default class NoteStatus extends Plugin {
|
|||
// this.workspaceIntegration.updateSettings(this.settings);
|
||||
|
||||
// // Actualizar componentes UI
|
||||
// this.statusBarController.updateSettings(this.settings);
|
||||
// this.statusBar.updateSettings(this.settings);
|
||||
}
|
||||
|
||||
onunload() {
|
||||
|
|
@ -285,6 +282,6 @@ export default class NoteStatus extends Plugin {
|
|||
// this.styleService.unload();
|
||||
|
||||
// // Limpiar componentes UI
|
||||
// this.statusBarController.unload();
|
||||
// this.statusBar.unload();
|
||||
}
|
||||
}
|
||||
|
|
@ -105,14 +105,6 @@ export class StatusService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the primary status of a file (first one, or 'unknown')
|
||||
*/
|
||||
public getFilePrimaryStatus(file: TFile): string {
|
||||
const statuses = this.getFileStatuses(file);
|
||||
return statuses[0] || 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon for a given status
|
||||
*/
|
||||
|
|
@ -213,7 +205,7 @@ export class StatusService {
|
|||
/**
|
||||
* Centralizes all status modification operations
|
||||
*/
|
||||
public async modifyNoteStatus(options: {
|
||||
private async modifyNoteStatus(options: {
|
||||
files: TFile | TFile[];
|
||||
statuses: string | string[];
|
||||
operation: 'set' | 'add' | 'remove' | 'toggle';
|
||||
|
|
|
|||
|
|
@ -32,6 +32,20 @@ export class StyleService {
|
|||
this.updateDynamicStyles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the dynamic styles based on current settings
|
||||
*/
|
||||
private updateDynamicStyles(): void {
|
||||
if (!this.dynamicStyleEl) {
|
||||
this.initializeDynamicStyles();
|
||||
return;
|
||||
}
|
||||
|
||||
const allColors = this.getAllStatusColors();
|
||||
const cssRules = this.generateColorCssRules(allColors);
|
||||
this.dynamicStyleEl.textContent = cssRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all status colors including those from enabled templates
|
||||
*/
|
||||
|
|
@ -55,20 +69,6 @@ export class StyleService {
|
|||
return colors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the dynamic styles based on current settings
|
||||
*/
|
||||
public updateDynamicStyles(): void {
|
||||
if (!this.dynamicStyleEl) {
|
||||
this.initializeDynamicStyles();
|
||||
return;
|
||||
}
|
||||
|
||||
const allColors = this.getAllStatusColors();
|
||||
const cssRules = this.generateColorCssRules(allColors);
|
||||
this.dynamicStyleEl.textContent = cssRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate CSS rules for status colors
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue