Skip to content

Commit

Permalink
feat(settings): expose items in setting tabs in api; fix OldConfig def
Browse files Browse the repository at this point in the history
now setting tab is hidden when alx-folder-note is enabled
  • Loading branch information
aidenlx committed Sep 1, 2021
1 parent 562c978 commit 1b878d9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 34 deletions.
10 changes: 9 additions & 1 deletion src/fnc-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@ import VaultHandler from "./modules/vault-handler";
import { DEFAULT_SETTINGS, FNCoreSettings, FNCoreSettingTab } from "./settings";
import API from "./typings/api";

const ALX_FOLDER_NOTE = "alx-folder-note";
export default class FNCore extends Plugin {
settings: FNCoreSettings = DEFAULT_SETTINGS;
vaultHandler = new VaultHandler(this);
finder: NoteFinder;
api: API;

settingTab = new FNCoreSettingTab(this);

constructor(app: App, manifest: PluginManifest) {
super(app, manifest);
let finder = new NoteFinder(this);
this.finder = finder;
let plugin = this;
this.api = {
get renderCoreSettings() {
return plugin.settingTab.renderCoreSettings;
},
importSettings: (cfg) => {
if (cfg.folderNotePref !== undefined) {
switch (cfg.folderNotePref) {
Expand Down Expand Up @@ -73,7 +80,8 @@ export default class FNCore extends Plugin {

await this.loadSettings();

this.addSettingTab(new FNCoreSettingTab(this.app, this));
if (!this.app.plugins.enabledPlugins.has(ALX_FOLDER_NOTE))
this.addSettingTab(this.settingTab);

AddOptionsForNote(this);
AddOptionsForFolder(this);
Expand Down
62 changes: 30 additions & 32 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface FNCoreSettings {
deleteOutsideNoteWithFolder: boolean;
indexName: string;
modifierForNewNote: Modifier;
hideNoteInExplorer: boolean;
autoRename: boolean;
folderNoteTemplate: string;
}
Expand All @@ -18,36 +17,35 @@ export const DEFAULT_SETTINGS: FNCoreSettings = {
deleteOutsideNoteWithFolder: true,
indexName: "_about_",
modifierForNewNote: "Meta",
hideNoteInExplorer: true,
autoRename: true,
folderNoteTemplate: "# {{FOLDER_NAME}}",
};

export class FNCoreSettingTab extends PluginSettingTab {
plugin: FNCore;

constructor(app: App, plugin: FNCore) {
super(app, plugin);
this.plugin = plugin;
constructor(public plugin: FNCore) {
super(plugin.app, plugin);
}

display(): void {
let { containerEl } = this;
containerEl.empty();
this.renderCoreSettings(containerEl);
}

this.setNoteLoc();
renderCoreSettings = (target: HTMLElement) => {
this.setNoteLoc(target);
if (this.plugin.settings.folderNotePref === NoteLoc.Index)
this.setIndexName();
this.setIndexName(target);
else if (this.plugin.settings.folderNotePref === NoteLoc.Outside)
this.setDeleteWithFolder();
this.setTemplate();
this.setModifier();
this.setDeleteWithFolder(target);
this.setTemplate(target);
this.setModifier(target);
if (this.plugin.settings.folderNotePref !== NoteLoc.Index)
this.setAutoRename();
}
this.setAutoRename(target);
};

setDeleteWithFolder() {
new Setting(this.containerEl)
setDeleteWithFolder = (containerEl: HTMLElement) => {
new Setting(containerEl)
.setName("Delete Outside Note with Folder")
.setDesc("Delete folder note outside when folder is deleted")
.addToggle((toggle) =>
Expand All @@ -58,9 +56,9 @@ export class FNCoreSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}),
);
}
setNoteLoc() {
new Setting(this.containerEl)
};
setNoteLoc = (containerEl: HTMLElement) => {
new Setting(containerEl)
.setName("Preference for Note File Location")
.setDesc(
createFragment((el) => {
Expand Down Expand Up @@ -94,9 +92,9 @@ export class FNCoreSettingTab extends PluginSettingTab {
this.display();
});
});
}
setIndexName() {
new Setting(this.containerEl)
};
setIndexName = (containerEl: HTMLElement) => {
new Setting(containerEl)
.setName("Name for Index File")
.setDesc("Set the note name to be recognized as index file for folders")
.addText((text) => {
Expand All @@ -109,9 +107,9 @@ export class FNCoreSettingTab extends PluginSettingTab {
.setValue(this.plugin.settings.indexName)
.onChange(debounce(onChange, 500, true));
});
}
setTemplate() {
new Setting(this.containerEl)
};
setTemplate = (containerEl: HTMLElement) => {
new Setting(containerEl)
.setName("Folder Note Template")
.setDesc(
createFragment((descEl) => {
Expand All @@ -133,9 +131,9 @@ export class FNCoreSettingTab extends PluginSettingTab {
text.inputEl.rows = 8;
text.inputEl.cols = 30;
});
}
setModifier() {
new Setting(this.containerEl)
};
setModifier = (containerEl: HTMLElement) => {
new Setting(containerEl)
.setName("Modifier for New Note")
.setDesc("Choose a modifier to click folders with to create folder notes")
.addDropdown((dropDown) => {
Expand Down Expand Up @@ -164,9 +162,9 @@ export class FNCoreSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
}
setAutoRename() {
new Setting(this.containerEl)
};
setAutoRename = (containerEl: HTMLElement) => {
new Setting(containerEl)
.setName("Auto Sync")
.setDesc("Keep name and location of folder note and folder in sync")
.addToggle((toggle) => {
Expand All @@ -176,5 +174,5 @@ export class FNCoreSettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
});
});
}
};
}
2 changes: 1 addition & 1 deletion src/typings/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ interface OldConfig {
deleteOutsideNoteWithFolder: boolean;
indexName: string;
modifierForNewNote: Modifier;
hideNoteInExplorer: boolean;
autoRename: boolean;
folderNoteTemplate: string;
}
export default interface FolderNoteAPI {
importSettings(settings: Partial<OldConfig>): void;
renderCoreSettings(target: HTMLElement): void;

getFolderFromNote(note: TFile | string): TFolder | null;

Expand Down
6 changes: 6 additions & 0 deletions src/typings/obsidian-ex.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ declare module "obsidian" {
interface Vault {
exists(normalizedPath: string, sensitive?: boolean): Promise<boolean>;
}

interface App {
plugins: {
enabledPlugins: Set<string>;
};
}
}

0 comments on commit 1b878d9

Please sign in to comment.