Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit a6d8e22

Browse files
committed
Kanban strategy for open as a custom view
1 parent ec23b3e commit a6d8e22

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

src/main.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import {
55
TFolder,
66
TFile,
77
ViewState,
8+
Platform,
9+
MarkdownView,
810
} from 'obsidian';
911

1012
import {
1113
DatabaseView,
12-
databaseIcon
14+
databaseIcon,
1315
} from 'DatabaseView';
1416

1517
import {
@@ -29,6 +31,8 @@ import { LOGGER } from 'services/Logger';
2931
import { DatabaseCore, DatabaseFrontmatterOptions, DEFAULT_SETTINGS, YAML_INDENT } from 'helpers/Constants';
3032
import { PreviewDatabaseModeService } from 'services/MarkdownPostProcessorService';
3133
import { unmountComponentAtNode } from 'react-dom';
34+
import { hasFrontmatterKey } from 'helpers/VaultManagement';
35+
import { getParentWindow } from 'helpers/WindowElement';
3236

3337
interface WindowRegistry {
3438
viewMap: Map<string, DatabaseView>;
@@ -311,7 +315,7 @@ export default class DBFolderPlugin extends Plugin {
311315

312316
registerEvents() {
313317
this.registerEvent(
314-
this.app.workspace.on('file-menu', (menu, file: TFile) => {
318+
this.app.workspace.on('file-menu', (menu, file: TFile, source, leaf) => {
315319
// Add a menu item to the folder context menu to create a database
316320
if (file instanceof TFolder) {
317321
menu.addItem((item) => {
@@ -320,6 +324,62 @@ export default class DBFolderPlugin extends Plugin {
320324
.setIcon(databaseIcon)
321325
.onClick(() => this.newDatabase(file));
322326
});
327+
return;
328+
}
329+
if (
330+
!Platform.isMobile &&
331+
file instanceof TFile &&
332+
leaf &&
333+
source === 'sidebar-context-menu' &&
334+
hasFrontmatterKey(file)
335+
) {
336+
const views = this.getDatabaseViews(
337+
getParentWindow(leaf.view.containerEl)
338+
);
339+
let haveDatabaseView = false;
340+
341+
for (const view of views) {
342+
if (view.file === file) {
343+
view.onPaneMenu(menu, 'more-options', false);
344+
haveDatabaseView = true;
345+
break;
346+
}
347+
}
348+
349+
if (!haveDatabaseView) {
350+
menu.addItem((item) => {
351+
item
352+
.setTitle('Open as database folder')
353+
.setIcon(databaseIcon)
354+
.setSection('pane')
355+
.onClick(() => {
356+
this.databaseFileModes[(leaf as any).id || file.path] =
357+
DatabaseCore.FRONTMATTER_KEY;
358+
this.setDatabaseView(leaf);
359+
});
360+
});
361+
362+
return;
363+
}
364+
}
365+
366+
if (
367+
leaf?.view instanceof MarkdownView &&
368+
file instanceof TFile &&
369+
source === 'pane-more-options' &&
370+
hasFrontmatterKey(file)
371+
) {
372+
menu.addItem((item) => {
373+
item
374+
.setTitle('Open as database folder')
375+
.setIcon(databaseIcon)
376+
.setSection('pane')
377+
.onClick(() => {
378+
this.databaseFileModes[(leaf as any).id || file.path] =
379+
DatabaseCore.FRONTMATTER_KEY;
380+
this.setDatabaseView(leaf);
381+
});
382+
});
323383
}
324384
})
325385
);

0 commit comments

Comments
 (0)