Skip to content

Commit

Permalink
feat: ✨ Options to choose which views are oppened onload
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 30, 2021
1 parent b17398c commit c48c571
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 28 deletions.
40 changes: 40 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,46 @@ export class BCSettingTab extends PluginSettingTab {
})
);

new Setting(generalDetails)
.setName("Open Views by Default")
.setDesc("Choose which of the views to open onload")
.addToggle((toggle) => {
toggle
.setTooltip("Matrix View")
.setValue(settings.openMatrixOnLoad)
.onChange(async (value) => {
settings.openMatrixOnLoad = value;
await plugin.saveSettings();
});
})
.addToggle((toggle) => {
toggle
.setTooltip("Stats View")
.setValue(settings.openStatsOnLoad)
.onChange(async (value) => {
settings.openStatsOnLoad = value;
await plugin.saveSettings();
});
})
.addToggle((toggle) => {
toggle
.setTooltip("Ducks View")
.setValue(settings.openDuckOnLoad)
.onChange(async (value) => {
settings.openDuckOnLoad = value;
await plugin.saveSettings();
});
})
.addToggle((toggle) => {
toggle
.setTooltip("Down View")
.setValue(settings.openDownOnLoad)
.onChange(async (value) => {
settings.openDownOnLoad = value;
await plugin.saveSettings();
});
});

new Setting(generalDetails)
.setName("Enable Field Suggestor")
.setDesc(
Expand Down
26 changes: 4 additions & 22 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
import DownView from "./DownView";
import DucksView from "./DucksView";
import type {
BCSettings,
Directions,
Relations,
UserHier,
ViewInfo,
visTypes,
} from "./interfaces";
import MatrixView from "./MatrixView";
import StatsView from "./StatsView";

export const MATRIX_VIEW = "BC-matrix";
export const STATS_VIEW = "BC-stats";
export const DUCK_VIEW = "BC-ducks";
export const DOWN_VIEW = "BC-down";

export const VIEWS: ViewInfo[] = [
{
plain: "Matrix",
type: MATRIX_VIEW,
constructor: MatrixView,
openOnLoad: true,
},
{
plain: "Stats",
type: STATS_VIEW,
constructor: StatsView,
openOnLoad: true,
},
{ plain: "Duck", type: DUCK_VIEW, constructor: DucksView, openOnLoad: false },
{ plain: "Down", type: DOWN_VIEW, constructor: DownView, openOnLoad: true },
];

export const TRAIL_ICON = "BC-trail-icon";
export const TRAIL_ICON_SVG =
'<path fill="currentColor" stroke="currentColor" d="M48.8,4c-6,0-13.5,0.5-19.7,3.3S17.9,15.9,17.9,25c0,5,2.6,9.7,6.1,13.9s8.1,8.3,12.6,12.3s9,7.8,12.2,11.5 c3.2,3.7,5.1,7.1,5.1,10.2c0,14.4-13.4,19.3-13.4,19.3c-0.7,0.2-1.2,0.8-1.3,1.5s0.1,1.4,0.7,1.9c0.6,0.5,1.3,0.6,2,0.3 c0,0,16.1-6.1,16.1-23c0-4.6-2.6-8.8-6.1-12.8c-3.5-4-8.1-7.9-12.6-11.8c-4.5-3.9-8.9-7.9-12.2-11.8c-3.2-3.9-5.2-7.7-5.2-11.4 c0-7.8,3.6-11.6,8.8-14S43,8,48.8,8c4.6,0,9.3,0,11,0c0.7,0,1.4-0.4,1.7-1c0.3-0.6,0.3-1.4,0-2s-1-1-1.7-1C58.3,4,53.4,4,48.8,4 L48.8,4z M78.1,4c-0.6,0-1.2,0.2-1.6,0.7l-8.9,9.9c-0.5,0.6-0.7,1.4-0.3,2.2c0.3,0.7,1,1.2,1.8,1.2h0.1l-2.8,2.6 c-0.6,0.6-0.8,1.4-0.5,2.2c0.3,0.8,1,1.3,1.9,1.3h1.3l-4.5,4.6c-0.6,0.6-0.7,1.4-0.4,2.2c0.3,0.7,1,1.2,1.8,1.2h10v4 c0,0.7,0.4,1.4,1,1.8c0.6,0.4,1.4,0.4,2,0c0.6-0.4,1-1,1-1.8v-4h10c0.8,0,1.5-0.5,1.8-1.2c0.3-0.7,0.1-1.6-0.4-2.2L86.9,24h1.3 c0.8,0,1.6-0.5,1.9-1.3c0.3-0.8,0.1-1.6-0.5-2.2l-2.8-2.6h0.1c0.8,0,1.5-0.5,1.8-1.2c0.3-0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2,3.8,84,4.2,84.8C4.5,85.5,5.2,86,6,86h16v5.4c0,0.7,0.4,1.4,1,1.8c0.6,0.4,1.4,0.4,2,0c0.6-0.4,1-1,1-1.8V86h16 c0.8,0,1.5-0.5,1.8-1.2c0.3-0.7,0.1-1.6-0.4-2.2L35,74h4.4c0.8,0,1.5-0.5,1.8-1.2s0.2-1.6-0.4-2.2l-6.5-6.8h3 c0.8,0,1.5-0.5,1.8-1.2c0.3-0.7,0.2-1.6-0.4-2.2L25.4,46.6C25.1,46.2,24.5,46,24,46L24,46z M24,50.9l8.7,9h-3 c-0.8,0-1.5,0.5-1.8,1.2s-0.2,1.6,0.4,2.2l6.5,6.8h-4.5c-0.8,0-1.5,0.5-1.8,1.2c-0.3,0.7-0.1,1.6,0.4,2.2l8.5,8.6H10.8l8.5-8.6 c0.6-0.6,0.7-1.4,0.4-2.2c-0.3-0.7-1-1.2-1.8-1.2h-4.5l6.5-6.8c0.6-0.6,0.7-1.4,0.4-2.2c-0.3-0.7-1-1.2-1.8-1.2h-3L24,50.9z"/>';
Expand Down Expand Up @@ -169,6 +147,10 @@ export const DEFAULT_SETTINGS: BCSettings = {
HNUpField: "",
refreshOnNoteChange: false,
useAllMetadata: true,
openMatrixOnLoad: true,
openStatsOnLoad: true,
openDuckOnLoad: false,
openDownOnLoad: true,
parseJugglLinksWithoutJuggl: false,
showNameOrType: true,
showRelationType: true,
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface BCSettings {
limitTrailCheckboxStates: { [field: string]: boolean };
limitWriteBCCheckboxStates: { [field: string]: boolean };
noPathMessage: string;
openMatrixOnLoad: boolean;
openStatsOnLoad: boolean;
openDuckOnLoad: boolean;
openDownOnLoad: boolean;
parseJugglLinksWithoutJuggl: boolean;
refreshOnNoteChange: boolean;
respectReadableLineLength: boolean;
Expand Down
48 changes: 42 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import {
copy,
openView,
} from "obsidian-community-lib/dist/utils";
import StatsView from "./StatsView";
import DownView from "./DownView";
import DucksView from "./DucksView";
import MatrixView from "./MatrixView";
import { Debugger } from "src/Debugger";
import util from "util";
import { BCSettingTab } from "./BreadcrumbsSettingTab";
Expand All @@ -35,12 +39,14 @@ import {
BC_TAG_NOTE_FIELD,
BC_TRAVERSE_NOTE,
DEFAULT_SETTINGS,
DOWN_VIEW,
dropHeaderOrAlias,
DUCK_VIEW,
MATRIX_VIEW,
splitLinksRegex,
STATS_VIEW,
TRAIL_ICON,
TRAIL_ICON_SVG,
VIEWS,
} from "./constants";
import { FieldSuggestor } from "./FieldSuggestor";
import {
Expand All @@ -64,6 +70,7 @@ import type {
JugglLink,
MyView,
RawValue,
ViewInfo,
} from "./interfaces";
import {
createOrUpdateYaml,
Expand All @@ -88,12 +95,14 @@ export default class BCPlugin extends Plugin {
layoutChange: EventRef = undefined;
statusBatItemEl: HTMLElement = undefined;
db: Debugger;
VIEWS: ViewInfo[];

async refreshIndex() {
if (!this.activeLeafChange) this.registerActiveLeafChangeEvent();
if (!this.layoutChange) this.registerLayoutChangeEvent();
this.mainG = await this.initGraphs();
for (const view of VIEWS) await this.getActiveTYPEView(view.type)?.draw();
for (const view of this.VIEWS)
await this.getActiveTYPEView(view.type)?.draw();
if (this.settings.showTrail) await this.drawTrail();
if (this.settings.showRefreshNotice) new Notice("Index refreshed");
}
Expand Down Expand Up @@ -125,7 +134,7 @@ export default class BCPlugin extends Plugin {
const { settings } = this;
this.mainG = await this.initGraphs();

for (const view of VIEWS) {
for (const view of this.VIEWS) {
if (view.openOnLoad)
await openView(this.app, view.type, view.constructor);
}
Expand Down Expand Up @@ -169,7 +178,34 @@ export default class BCPlugin extends Plugin {
}
}

for (const view of VIEWS) {
this.VIEWS = [
{
plain: "Matrix",
type: MATRIX_VIEW,
constructor: MatrixView,
openOnLoad: this.settings.openMatrixOnLoad,
},
{
plain: "Stats",
type: STATS_VIEW,
constructor: StatsView,
openOnLoad: this.settings.openStatsOnLoad,
},
{
plain: "Duck",
type: DUCK_VIEW,
constructor: DucksView,
openOnLoad: this.settings.openDuckOnLoad,
},
{
plain: "Down",
type: DOWN_VIEW,
constructor: DownView,
openOnLoad: this.settings.openDownOnLoad,
},
];

for (const view of this.VIEWS) {
this.registerView(
view.type,
(leaf: WorkspaceLeaf) => new view.constructor(leaf, this)
Expand All @@ -196,7 +232,7 @@ export default class BCPlugin extends Plugin {

addIcon(TRAIL_ICON, TRAIL_ICON_SVG);

for (const view of VIEWS) {
for (const view of this.VIEWS) {
this.addCommand({
id: `show-${view.type}-view`,
name: `Open ${view.plain} View`,
Expand Down Expand Up @@ -362,7 +398,7 @@ export default class BCPlugin extends Plugin {
};

getActiveTYPEView(type: string): MyView | null {
const { constructor } = VIEWS.find((view) => view.type === type);
const { constructor } = this.VIEWS.find((view) => view.type === type);
const leaves = this.app.workspace.getLeavesOfType(type);
if (leaves && leaves.length >= 1) {
const view = leaves[0].view;
Expand Down

0 comments on commit c48c571

Please sign in to comment.