Skip to content

Commit

Permalink
Settings parity + infra
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 23, 2024
1 parent 0723984 commit de33818
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 160 deletions.
63 changes: 27 additions & 36 deletions src/modals/CreateListIndexModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type BreadcrumbsPlugin from "src/main";
import { _add_settings_show_node_options } from "src/settings/ShowNodeOptions";
import { active_file_store } from "src/stores/active_file";
import { stringify_hierarchy } from "src/utils/hierarchies";
import { new_setting } from "src/utils/settings";
import { get } from "svelte/store";

export class CreateListIndexModal extends Modal {
Expand Down Expand Up @@ -75,44 +76,34 @@ export class CreateListIndexModal extends Modal {
});
});

new Setting(contentEl)
.setName("Direction")
.setDesc("Direction to traverse")
.addDropdown((dropdown) => {
DIRECTIONS.forEach((dir) => {
dropdown.addOption(dir, dir);
});

dropdown.setValue(this.options.dir);

dropdown.onChange((value) => {
this.options.dir = value as Direction;
});
});

new Setting(contentEl)
.setName("Link Kind")
.setDesc("Format to use for links")
.addDropdown((dropdown) => {
LINK_KINDS.forEach((kind) => {
dropdown.addOption(kind, kind);
});

dropdown.setValue(this.options.link_kind);
new_setting(contentEl, {
name: "Direction",
desc: "Direction to traverse",
select: {
options: DIRECTIONS,
value: this.options.dir,
cb: (value) => (this.options.dir = value),
},
});

dropdown.onChange((value) => {
this.options.link_kind = value as LinkKind;
});
});
new_setting(contentEl, {
name: "Link Kind",
desc: "Format to use for links",
select: {
options: LINK_KINDS,
value: this.options.link_kind,
cb: (value) => (this.options.link_kind = value),
},
});

new Setting(contentEl)
.setName("Indent")
.setDesc("Indentation to use for each level")
.addText((text) => {
text.setValue(this.options.indent).onChange((value) => {
this.options.indent = value;
});
});
new_setting(contentEl, {
name: "Indent",
desc: "Indentation to use for each level",
input: {
value: this.options.indent,
cb: (value) => (this.options.indent = value),
},
});

_add_settings_show_node_options(
plugin,
Expand Down
164 changes: 78 additions & 86 deletions src/modals/ImpliedRelationshipsSettingsModal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { App, MarkdownRenderer, Modal, Setting } from "obsidian";
import type BreadcrumbsPlugin from "src/main";
import { new_setting } from "src/utils/settings";

export class ImpliedRelationshipsSettingsModal extends Modal {
plugin: BreadcrumbsPlugin;
Expand Down Expand Up @@ -39,57 +40,52 @@ export class ImpliedRelationshipsSettingsModal extends Modal {
plugin.refresh();
};

new Setting(contentEl)
.setName("Current Note is Sibling")
.setDesc("The current note is it's own implied sibling.")
.addToggle((tg) =>
tg
.setValue(implied_relationships.self_is_sibling)
.onChange(async (val) => {
implied_relationships.self_is_sibling = val;

await save();
}),
);
new_setting(contentEl, {
name: "Current Note is Sibling",
desc: "The current note is it's own implied sibling.",
toggle: {
value: implied_relationships.self_is_sibling,
cb: async (val) => {
implied_relationships.self_is_sibling = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
Me -.->|same| Me`,
);

new Setting(contentEl)
.setName("Opposite Direction")
.setDesc(
"An explicit relationship in one direction implies the opposite direction.",
)
.addToggle((tg) =>
tg
.setValue(implied_relationships.opposite_direction)
.onChange(async (val) => {
implied_relationships.opposite_direction = val;

await save();
}),
);
new_setting(contentEl, {
name: "Opposite Direction",
desc: "An explicit relationship in one direction implies the opposite direction.",
toggle: {
value: implied_relationships.opposite_direction,
cb: async (val) => {
implied_relationships.opposite_direction = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
A -->|up| B
B -.->|down| A`,
);

new Setting(contentEl)
.setName("Same Parent -> Siblings")
.setDesc("If two notes share a parent, they are siblings.")
.addToggle((tg) =>
tg
.setValue(implied_relationships.same_parent_is_sibling)
.onChange(async (val) => {
implied_relationships.same_parent_is_sibling = val;

await save();
}),
);
new_setting(contentEl, {
name: "Same Parent -> Siblings",
desc: "If two notes share a parent, they are siblings.",
toggle: {
value: implied_relationships.same_parent_is_sibling,
cb: async (val) => {
implied_relationships.same_parent_is_sibling = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
Expand All @@ -98,18 +94,17 @@ export class ImpliedRelationshipsSettingsModal extends Modal {
Me <-.->|same| Sister`,
);

new Setting(contentEl)
.setName("Same Siblings -> Siblings")
.setDesc("Treat your siblings' siblings as your siblings")
.addToggle((tg) =>
tg
.setValue(implied_relationships.same_sibling_is_sibling)
.onChange(async (val) => {
implied_relationships.same_sibling_is_sibling = val;

await save();
}),
);
new_setting(contentEl, {
name: "Same Siblings -> Siblings",
desc: "Treat your siblings' siblings as your siblings",
toggle: {
value: implied_relationships.same_sibling_is_sibling,
cb: async (val) => {
implied_relationships.same_sibling_is_sibling = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
Expand All @@ -118,18 +113,17 @@ export class ImpliedRelationshipsSettingsModal extends Modal {
Sister <-.->|same| Brother`,
);

new Setting(contentEl)
.setName("Siblings' Parent -> Parent")
.setDesc("Your siblings' parents are your parents")
.addToggle((tg) =>
tg
.setValue(implied_relationships.siblings_parent_is_parent)
.onChange(async (val) => {
implied_relationships.siblings_parent_is_parent = val;

await save();
}),
);
new_setting(contentEl, {
name: "Siblings' Parent -> Parent",
desc: "Your siblings' parents are your parents",
toggle: {
value: implied_relationships.siblings_parent_is_parent,
cb: async (val) => {
implied_relationships.siblings_parent_is_parent = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
Expand All @@ -138,18 +132,17 @@ export class ImpliedRelationshipsSettingsModal extends Modal {
Me -.->|up| Dad`,
);

new Setting(contentEl)
.setName("Aunt/Uncle")
.setDesc("Your parent's siblings are your parents (aunts/uncles)")
.addToggle((tg) =>
tg
.setValue(implied_relationships.parents_sibling_is_parent)
.onChange(async (val) => {
implied_relationships.parents_sibling_is_parent = val;

await save();
}),
);
new_setting(contentEl, {
name: "Aunt/Uncle",
desc: "Your parent's siblings are your parents (aunts/uncles)",
toggle: {
value: implied_relationships.parents_sibling_is_parent,
cb: async (val) => {
implied_relationships.parents_sibling_is_parent = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
Expand All @@ -158,18 +151,17 @@ export class ImpliedRelationshipsSettingsModal extends Modal {
Me -.->|up| Uncle`,
);

new Setting(contentEl)
.setName("Cousins")
.setDesc("Parents' siblings' children are siblings (cousins)")
.addToggle((tg) =>
tg
.setValue(implied_relationships.cousing_is_sibling)
.onChange(async (val) => {
implied_relationships.cousing_is_sibling = val;

await save();
}),
);
new_setting(contentEl, {
name: "Cousins",
desc: "Parents' siblings' children are siblings (cousins)",
toggle: {
value: implied_relationships.cousing_is_sibling,
cb: async (val) => {
implied_relationships.cousing_is_sibling = val;
await save();
},
},
});

render_mermaid_diagram(
`flowchart LR
Expand Down
72 changes: 72 additions & 0 deletions src/settings/DendronNoteSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Notice } from "obsidian";
import type BreadcrumbsPlugin from "src/main";
import { new_setting } from "src/utils/settings";

export const _add_settings_dendron_note = (
plugin: BreadcrumbsPlugin,
containerEl: HTMLElement,
) => {
new_setting(containerEl, {
name: "Enabled",
desc: "Look for dendron notes to use as edge sources",
toggle: {
value: plugin.settings.explicit_edge_sources.dendron_note.enabled,
cb: async (value) => {
plugin.settings.explicit_edge_sources.dendron_note.enabled =
value;
plugin.refresh();
await plugin.saveSettings();
},
},
});

new_setting(containerEl, {
name: "Delimiter",
desc: "Delimiter to use to split the note name",
input: {
value: plugin.settings.explicit_edge_sources.dendron_note.delimiter,
cb: async (value) => {
if (!value) new Notice("Delimiter cannot be empty");
else {
plugin.settings.explicit_edge_sources.dendron_note.delimiter =
value;
plugin.refresh();
await plugin.saveSettings();
}
},
},
});

new_setting(containerEl, {
name: "Default Field",
desc: "Field to use if the BC-dendron-note-field is not specified",
select: {
value: plugin.settings.explicit_edge_sources.dendron_note
.default_field,
options: plugin.settings.hierarchies
.map((h) => Object.values(h.dirs))
.flat(2),
cb: async (value) => {
plugin.settings.explicit_edge_sources.dendron_note.default_field =
value;
plugin.refresh();
await plugin.saveSettings();
},
},
});

new_setting(containerEl, {
name: "Display Trimmed",
desc: "Display Dendron note names as the right-most split of the delimiter. e.g. `a.b.c` -> `c`",
toggle: {
value: plugin.settings.explicit_edge_sources.dendron_note
.display_trimmed,
cb: async (value) => {
plugin.settings.explicit_edge_sources.dendron_note.display_trimmed =
value;
plugin.refresh();
await plugin.saveSettings();
},
},
});
};
Loading

0 comments on commit de33818

Please sign in to comment.