Skip to content

Commit

Permalink
Fixed hide collapse icon bug & more
Browse files Browse the repository at this point in the history
Fixed that the file explorer always updates when changing a tab in the plugin settings

Changed the setting name for the css class that stops white space collapsing for less confusing with the name
  • Loading branch information
LostPaul committed Jan 27, 2024
1 parent 35e53aa commit 4371aa5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 30 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "folder-notes",
"name": "Folder notes",
"version": "1.7.5",
"version": "1.7.6",
"minAppVersion": "0.15.0",
"description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.",
"author": "Lost Paul",
Expand Down
17 changes: 11 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class FolderNotesPlugin extends Plugin {
mouseEvent: MouseEvent | null = null;
hoverLinkTriggered = false;
tabManager: TabManager;
settingsOpened = false;
async onload() {
console.log('loading folder notes plugin');
await this.loadSettings();
Expand All @@ -38,7 +39,7 @@ export default class FolderNotesPlugin extends Plugin {
if (this.settings.boldNameInPath) { document.body.classList.add('folder-note-bold-path'); }
if (this.settings.cursiveNameInPath) { document.body.classList.add('folder-note-cursive-path'); }
if (this.settings.underlineFolderInPath) { document.body.classList.add('folder-note-underline-path'); }
if (!this.settings.allowWhitespaceCollapsing) { document.body.classList.add('fn-whitespace-stop-collapsing'); }
if (this.settings.stopWhitespaceCollapsing) { document.body.classList.add('fn-whitespace-stop-collapsing'); }
if (this.settings.hideCollapsingIcon) { document.body.classList.add('fn-hide-collapse-icon'); }

new Commands(this.app, this).registerCommands();
Expand Down Expand Up @@ -179,10 +180,10 @@ export default class FolderNotesPlugin extends Plugin {
}

if (file instanceof TFile) {
const folderName = extractFolderName(this.settings.folderNoteName, file.basename);
const folder = getFolder(this, file);
if (!(folder instanceof TFolder)) { return; }
if (folderName !== folder.name) { return; }
this.addCSSClassToTitleEL(folder.path, 'has-folder-note');
this.addCSSClassToTitleEL(file.path, 'is-folder-note');
}
if (!this.app.workspace.layoutReady) return;

Expand Down Expand Up @@ -368,16 +369,18 @@ export default class FolderNotesPlugin extends Plugin {
} else if (folder.children.length > 1) {
if (attachmentsAreInRootFolder) {
return false;
} else if (this.settings.ignoreAttachmentFolder) {
} else if (this.settings.ignoreAttachmentFolder && this.app.vault.getAbstractFileByPath(`${folder.path}/${cleanAttachmentFolderPath}`)) {
const folderPath = `${folder.path}/${cleanAttachmentFolderPath}`
const attachmentFolder = this.app.vault.getAbstractFileByPath(folderPath);

if (attachmentFolder instanceof TFolder) {
if (!folder.collapsed) {
this.getEL(folder.path)?.click();
}
return attachmentFolder.children.length <= 2;
return folder.children.length <= 2;
}
} else {
return false;
}
}
return true;
Expand Down Expand Up @@ -532,6 +535,8 @@ export default class FolderNotesPlugin extends Plugin {
async saveSettings() {
await this.saveData(this.settings);
// cleanup any css if we need too
if (!this.settingsOpened) {
this.loadFileClasses(true);
}
}
}
4 changes: 2 additions & 2 deletions src/settings/FileExplorerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export async function renderFileExplorer(settingsTab: SettingsTab) {
.setDesc('Only open folder notes in the file explorer by clicking on the folder name')
.addToggle((toggle) =>
toggle
.setValue(settingsTab.plugin.settings.allowWhitespaceCollapsing)
.setValue(!settingsTab.plugin.settings.stopWhitespaceCollapsing)
.onChange(async (value) => {
if (!value) {
document.body.classList.add('fn-whitespace-stop-collapsing');
} else {
document.body.classList.remove('fn-whitespace-stop-collapsing');
}
settingsTab.plugin.settings.allowWhitespaceCollapsing = value;
settingsTab.plugin.settings.stopWhitespaceCollapsing = !value;
await settingsTab.plugin.saveSettings();
})
);
Expand Down
35 changes: 16 additions & 19 deletions src/settings/PathSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,22 @@ export async function renderPath(settingsTab: SettingsTab) {

settingsTab.settingsPage.createEl('h3', { text: 'Style settings' });

if (settingsTab.plugin.settings.openFolderNoteOnClickInPath) {
new Setting(containerEl)
.setName('Underline folders in the path')
.setDesc('Add an underline to folders that have a folder note in the path above a note')
.addToggle((toggle) =>
toggle
.setValue(settingsTab.plugin.settings.underlineFolderInPath)
.onChange(async (value) => {
settingsTab.plugin.settings.underlineFolderInPath = value;
if (value) {
document.body.classList.add('folder-note-underline-path');
} else {
document.body.classList.remove('folder-note-underline-path');
}
await settingsTab.plugin.saveSettings();
})
);
}
new Setting(containerEl)
.setName('Underline folders in the path')
.setDesc('Add an underline to folders that have a folder note in the path above a note')
.addToggle((toggle) =>
toggle
.setValue(settingsTab.plugin.settings.underlineFolderInPath)
.onChange(async (value) => {
settingsTab.plugin.settings.underlineFolderInPath = value;
if (value) {
document.body.classList.add('folder-note-underline-path');
} else {
document.body.classList.remove('folder-note-underline-path');
}
await settingsTab.plugin.saveSettings();
})
);

new Setting(containerEl)
.setName('Bold folders in the path')
Expand Down Expand Up @@ -87,5 +85,4 @@ export async function renderPath(settingsTab: SettingsTab) {
await settingsTab.plugin.saveSettings();
})
);

}
9 changes: 7 additions & 2 deletions src/settings/SettingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface FolderNotesSettings {
showDeleteConfirmation: boolean;
showRenameConfirmation: boolean;
underlineFolder: boolean;
allowWhitespaceCollapsing: boolean;
stopWhitespaceCollapsing: boolean;
underlineFolderInPath: boolean;
openFolderNoteOnClickInPath: boolean;
openInNewTab: boolean;
Expand Down Expand Up @@ -67,7 +67,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
excludeFolders: [],
showDeleteConfirmation: true,
underlineFolder: true,
allowWhitespaceCollapsing: false,
stopWhitespaceCollapsing: false,
underlineFolderInPath: true,
openFolderNoteOnClickInPath: true,
openInNewTab: false,
Expand Down Expand Up @@ -194,6 +194,7 @@ export class SettingsTab extends PluginSettingTab {
}

display(): void {
this.plugin.settingsOpened = true;
const { containerEl } = this;

containerEl.empty();
Expand Down Expand Up @@ -264,4 +265,8 @@ export class SettingsTab extends PluginSettingTab {
});
new Notice('Finished switching storage location');
}

onClose(): void {
this.plugin.settingsOpened = false;
}
}

0 comments on commit 4371aa5

Please sign in to comment.