Skip to content

Commit

Permalink
feat: ✨ Option to limit which fields are used in `Jump to first <dire…
Browse files Browse the repository at this point in the history
…ction>` command (fix #204)
  • Loading branch information
SkepticMystic committed Dec 16, 2021
1 parent cc9fdc1 commit eeb470c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 106 deletions.
81 changes: 33 additions & 48 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21021,6 +21021,7 @@ const DEFAULT_SETTINGS = {
showGrid: true,
showPrevNext: true,
limitTrailCheckboxes: [],
limitJumpToFirstFields: [],
showAll: false,
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
Expand Down Expand Up @@ -25007,16 +25008,6 @@ class BCSettingTab extends require$$0.PluginSettingTab {
});
const generalDetails = containerEl.createEl("details");
generalDetails.createEl("summary", { text: "General Options" });
new require$$0.Setting(generalDetails)
.setName("CSV Breadcrumb Paths")
.setDesc("The file path of a csv files with breadcrumbs information.")
.addText((text) => {
text.setValue(settings.CSVPaths);
text.inputEl.onblur = async () => {
settings.CSVPaths = text.inputEl.value;
await plugin.saveSettings();
};
});
new require$$0.Setting(generalDetails)
.setName("Show Refresh Index Notice")
.setDesc("When Refreshing Index, should it show a notice once the operation is complete?")
Expand Down Expand Up @@ -25106,6 +25097,17 @@ class BCSettingTab extends require$$0.PluginSettingTab {
settings.parseJugglLinksWithoutJuggl = value;
await plugin.saveSettings();
}));
generalDetails.createDiv().createEl("strong", {
text: "When running `Jump to first <direction>` command, limit which fields it can use.",
});
new Checkboxes({
target: generalDetails,
props: {
plugin: this.plugin,
settingName: "limitJumpToFirstFields",
options: getFields(settings.userHiers),
},
});
if (this.app.plugins.plugins.dataview !== undefined) {
new require$$0.Setting(generalDetails)
.setName("Dataview Wait Time")
Expand All @@ -25124,41 +25126,6 @@ class BCSettingTab extends require$$0.PluginSettingTab {
}
}));
}
// new Setting(generalDetails)
// .setName("Refresh Interval")
// .setDesc(
// "Enter an integer number of seconds to wait before Breadcrumbs auto-refreshes its data. This would update the matrix view and the trail if either are affected. (Set to 0 to disable autorefreshing)"
// )
// .addText((text) =>
// text
// .setPlaceholder("Seconds")
// .setValue(settings.refreshIntervalTime.toString())
// .onChange(async (value) => {
// clearInterval(plugin.refreshIntervalID);
// const num = Number(value);
// if (num > 0) {
// settings.refreshIntervalTime = num;
// await plugin.saveSettings();
// plugin.refreshIntervalID = window.setInterval(async () => {
// plugin.mainG = await plugin.initGraphs();
// if (settings.showTrail) {
// await plugin.drawTrail();
// }
// const activeMatrix = plugin.getActiveTYPEView(MATRIX_VIEW);
// if (activeMatrix) {
// await activeMatrix.draw();
// }
// }, num * 1000);
// plugin.registerInterval(plugin.refreshIntervalID);
// } else if (num === 0) {
// settings.refreshIntervalTime = num;
// await plugin.saveSettings();
// clearInterval(plugin.refreshIntervalID);
// } else {
// new Notice("The interval must be a non-negative number");
// }
// })
// );
const MLViewDetails = containerEl.createEl("details");
MLViewDetails.createEl("summary", { text: "Matrix/List View" });
new require$$0.Setting(MLViewDetails)
Expand Down Expand Up @@ -25437,6 +25404,16 @@ class BCSettingTab extends require$$0.PluginSettingTab {
alternativeHierarchyDetails.createEl("summary", {
text: "Alternative Hierarchies",
});
new require$$0.Setting(alternativeHierarchyDetails)
.setName("CSV Breadcrumb Paths")
.setDesc("The file path of a csv files with breadcrumbs information.")
.addText((text) => {
text.setValue(settings.CSVPaths);
text.inputEl.onblur = async () => {
settings.CSVPaths = text.inputEl.value;
await plugin.saveSettings();
};
});
new require$$0.Setting(alternativeHierarchyDetails)
.setName("Add Dendron notes to graph")
.setDesc("Dendron notes create a hierarchy using note names.\n`math.algebra` is a note about algebra, whose parent is `math`.\n`math.calculus.limits` is a note about limits whose parent is the note `math.calculus`, whose parent is `math`.")
Expand Down Expand Up @@ -51614,7 +51591,9 @@ class BCPlugin extends require$$0.Plugin {
await this.saveSettings();
}
if (!settings.CHECKBOX_STATES_OVERWRITTEN) {
settings.limitWriteBCCheckboxes = getFields(settings.userHiers);
const fields = getFields(settings.userHiers);
settings.limitWriteBCCheckboxes = fields;
settings.limitJumpToFirstFields = fields;
settings.limitTrailCheckboxes = getFields(settings.userHiers, "up");
settings.CHECKBOX_STATES_OVERWRITTEN = true;
await this.saveSettings();
Expand Down Expand Up @@ -51783,6 +51762,7 @@ class BCPlugin extends require$$0.Plugin {
id: `jump-to-first-${dir}`,
name: `Jump to first '${dir}'`,
callback: async () => {
var _a;
const file = this.app.workspace.getActiveFile();
if (!file) {
new require$$0.Notice("You need to be focussed on a Markdown file");
Expand All @@ -51795,8 +51775,13 @@ class BCPlugin extends require$$0.Plugin {
new require$$0.Notice(`No ${dir} found`);
return;
}
const toFile = this.app.metadataCache.getFirstLinkpathDest(allBCs[0].to, "");
this.app.workspace.activeLeaf.openFile(toFile);
const toNode = (_a = allBCs.find((bc) => settings.limitJumpToFirstFields.includes(bc.field))) === null || _a === void 0 ? void 0 : _a.to;
if (!toNode) {
new require$$0.Notice(`No note was found in ${dir} given the limited fields allowed: ${settings.limitJumpToFirstFields.join(", ")}`);
return;
}
const toFile = this.app.metadataCache.getFirstLinkpathDest(toNode, "");
await this.app.workspace.activeLeaf.openFile(toFile);
},
});
});
Expand Down
73 changes: 24 additions & 49 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@ export class BCSettingTab extends PluginSettingTab {
const generalDetails: HTMLDetailsElement = containerEl.createEl("details");
generalDetails.createEl("summary", { text: "General Options" });

new Setting(generalDetails)
.setName("CSV Breadcrumb Paths")
.setDesc("The file path of a csv files with breadcrumbs information.")
.addText((text) => {
text.setValue(settings.CSVPaths);
text.inputEl.onblur = async () => {
settings.CSVPaths = text.inputEl.value;
await plugin.saveSettings();
};
});

new Setting(generalDetails)
.setName("Show Refresh Index Notice")
.setDesc(
Expand Down Expand Up @@ -240,6 +229,19 @@ export class BCSettingTab extends PluginSettingTab {
})
);

const jumpToFirstFieldsDiv = generalDetails.createDiv().createEl("strong", {
text: "When running `Jump to first <direction>` command, limit which fields it can use.",
});

new Checkboxes({
target: generalDetails,
props: {
plugin: this.plugin,
settingName: "limitJumpToFirstFields",
options: getFields(settings.userHiers),
},
});

if (this.app.plugins.plugins.dataview !== undefined) {
new Setting(generalDetails)
.setName("Dataview Wait Time")
Expand All @@ -263,44 +265,6 @@ export class BCSettingTab extends PluginSettingTab {
);
}

// new Setting(generalDetails)
// .setName("Refresh Interval")
// .setDesc(
// "Enter an integer number of seconds to wait before Breadcrumbs auto-refreshes its data. This would update the matrix view and the trail if either are affected. (Set to 0 to disable autorefreshing)"
// )
// .addText((text) =>
// text
// .setPlaceholder("Seconds")
// .setValue(settings.refreshIntervalTime.toString())
// .onChange(async (value) => {
// clearInterval(plugin.refreshIntervalID);
// const num = Number(value);

// if (num > 0) {
// settings.refreshIntervalTime = num;
// await plugin.saveSettings();

// plugin.refreshIntervalID = window.setInterval(async () => {
// plugin.mainG = await plugin.initGraphs();
// if (settings.showTrail) {
// await plugin.drawTrail();
// }
// const activeMatrix = plugin.getActiveTYPEView(MATRIX_VIEW);
// if (activeMatrix) {
// await activeMatrix.draw();
// }
// }, num * 1000);
// plugin.registerInterval(plugin.refreshIntervalID);
// } else if (num === 0) {
// settings.refreshIntervalTime = num;
// await plugin.saveSettings();
// clearInterval(plugin.refreshIntervalID);
// } else {
// new Notice("The interval must be a non-negative number");
// }
// })
// );

const MLViewDetails: HTMLDetailsElement = containerEl.createEl("details");
MLViewDetails.createEl("summary", { text: "Matrix/List View" });

Expand Down Expand Up @@ -689,6 +653,17 @@ export class BCSettingTab extends PluginSettingTab {
text: "Alternative Hierarchies",
});

new Setting(alternativeHierarchyDetails)
.setName("CSV Breadcrumb Paths")
.setDesc("The file path of a csv files with breadcrumbs information.")
.addText((text) => {
text.setValue(settings.CSVPaths);
text.inputEl.onblur = async () => {
settings.CSVPaths = text.inputEl.value;
await plugin.saveSettings();
};
});

new Setting(alternativeHierarchyDetails)
.setName("Add Dendron notes to graph")
.setDesc(
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
showGrid: true,
showPrevNext: true,
limitTrailCheckboxes: [],
limitJumpToFirstFields: [],
showAll: false,
noPathMessage: `This note has no real or implied parents`,
trailSeperator: "→",
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface BCSettings {
limitTrailCheckboxes: string[];
/** An array of fields in all directions which **will** get written when running `Write implied BCs to file` */
limitWriteBCCheckboxes: string[];
limitJumpToFirstFields: string[];
CHECKBOX_STATES_OVERWRITTEN: boolean;
noPathMessage: string;
openMatrixOnLoad: boolean;
Expand Down
30 changes: 21 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ export default class BCPlugin extends Plugin {
}

if (!settings.CHECKBOX_STATES_OVERWRITTEN) {
settings.limitWriteBCCheckboxes = getFields(settings.userHiers);
const fields = getFields(settings.userHiers);
settings.limitWriteBCCheckboxes = fields;
settings.limitJumpToFirstFields = fields;
settings.limitTrailCheckboxes = getFields(settings.userHiers, "up");
settings.CHECKBOX_STATES_OVERWRITTEN = true;
await this.saveSettings();
Expand Down Expand Up @@ -379,7 +381,7 @@ export default class BCPlugin extends Plugin {
},
});

["up", "down", "next", "prev"].forEach((dir) => {
["up", "down", "next", "prev"].forEach((dir: Directions) => {
this.addCommand({
id: `jump-to-first-${dir}`,
name: `Jump to first '${dir}'`,
Expand All @@ -390,22 +392,32 @@ export default class BCPlugin extends Plugin {
return;
}
const { basename } = file;
const realsNImplieds = getRealnImplied(
this,
basename,
dir as Directions
)[dir];

const realsNImplieds = getRealnImplied(this, basename, dir)[dir];
const allBCs = [...realsNImplieds.reals, ...realsNImplieds.implieds];
if (allBCs.length === 0) {
new Notice(`No ${dir} found`);
return;
}

const toNode = allBCs.find((bc) =>
settings.limitJumpToFirstFields.includes(bc.field)
)?.to;

if (!toNode) {
new Notice(
`No note was found in ${dir} given the limited fields allowed: ${settings.limitJumpToFirstFields.join(
", "
)}`
);
return;
}

const toFile = this.app.metadataCache.getFirstLinkpathDest(
allBCs[0].to,
toNode,
""
);
this.app.workspace.activeLeaf.openFile(toFile);
await this.app.workspace.activeLeaf.openFile(toFile);
},
});
});
Expand Down

0 comments on commit eeb470c

Please sign in to comment.