Skip to content

Commit

Permalink
feat: add bookmarks provider
Browse files Browse the repository at this point in the history
  • Loading branch information
nathonius committed Aug 5, 2023
1 parent 12a78ac commit e6a8a79
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

- Each set of commands now includes a "toggle" command as well as the collapse and expand commands.
- Support for search view
- Support for bookmarks view

## Fixes

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Commands can be toggled on or off in settings. Each set of commands has a collap
- Tag Pane
- Search
- Does not support collapse toggle, only expand and collapse
- Bookmarks
- Only supports toggle, may be a bit finnicky
- Global (all supported views)

## Changelog
Expand Down
6 changes: 4 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ export const DEFAULT_SETTINGS: Settings = {
Global: false,
FileExplorer: true,
TagPane: true,
Search: false
Search: false,
Bookmarks: false
}
};

export enum ProviderType {
FileExplorer = 'FileExplorer',
TagPane = 'TagPane',
Global = 'Global',
Search = 'Search'
Search = 'Search',
Bookmarks = 'Bookmarks'
}
4 changes: 3 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Plugin } from 'obsidian';
import { DEFAULT_SETTINGS, ProviderType } from './constants';
import { Settings } from './interfaces';
import {
BookmarksProvider,
FileExplorerProvider,
GlobalProvider,
SearchProvider,
Expand All @@ -17,7 +18,8 @@ export class CollapseAllPlugin extends Plugin {
[ProviderType.Global]: new GlobalProvider(this),
[ProviderType.FileExplorer]: new FileExplorerProvider(this),
[ProviderType.TagPane]: new TagPaneProvider(this),
[ProviderType.Search]: new SearchProvider(this)
[ProviderType.Search]: new SearchProvider(this),
[ProviderType.Bookmarks]: new BookmarksProvider(this)
};

get allProviders(): ProviderBase[] {
Expand Down
20 changes: 20 additions & 0 deletions src/provider/bookmarks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Command, WorkspaceLeaf } from 'obsidian';
import { ProviderType } from '../constants';
import { ProviderBase } from './base';

export class BookmarksProvider extends ProviderBase {
public readonly providerType = ProviderType.Bookmarks;
public readonly displayName = 'Bookmarks';
protected readonly leafType = 'bookmarks';
protected readonly toggleCommandName = 'Toggle collapse in bookmarks view';
protected readonly collapseCommandName = 'Not available';
protected readonly expandCommandName = 'Not available';

protected override get commands(): Command[] {
return [this.toggleCommand];
}

protected override collapseOrExpandAll(leaf: WorkspaceLeaf): void {
leaf.view.collapseOrExpandAllEl?.click();
}
}
1 change: 1 addition & 0 deletions src/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { FileExplorerProvider } from './file-explorer';
export { TagPaneProvider } from './tag-pane';
export { GlobalProvider } from './global';
export { SearchProvider } from './search';
export { BookmarksProvider } from './bookmarks';
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ declare module 'obsidian' {
toggleCollapseAll: () => void;
setCollapseAll: (collapse: boolean) => void;
isAllCollapsed: boolean;
collapseOrExpandAllEl: HTMLDivElement;
}
}

0 comments on commit e6a8a79

Please sign in to comment.