mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Edit overview button & create folder note for every existing folder
This commit is contained in:
parent
b796389d37
commit
80193b9b58
5 changed files with 66 additions and 32 deletions
|
|
@ -54,9 +54,10 @@ export class ExcludePattern {
|
|||
export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) {
|
||||
const folderName = plugin.getFolderNameFromPathString(path);
|
||||
const matchedPattern = getExcludedFolderByPattern(plugin, folderName);
|
||||
console.log(matchedPattern);
|
||||
if (matchedPattern) { return matchedPattern; }
|
||||
|
||||
const excludedFolder = getExcludedFolderByPath(plugin, path);
|
||||
if (excludedFolder?.path === '') { return; }
|
||||
return excludedFolder;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { MarkdownPostProcessorContext, parseYaml, TAbstractFile, TFolder, TFile } from 'obsidian';
|
||||
import { extractFolderName, getFolderNote } from './functions/folderNoteFunctions';
|
||||
import FolderNotesPlugin from './main';
|
||||
import { FolderOverviewSettings } from './modals/folderOverview';
|
||||
export type yamlSettings = {
|
||||
title?: string;
|
||||
disableTitle?: boolean;
|
||||
|
|
@ -46,6 +47,7 @@ export function createOverview(plugin: FolderNotesPlugin, source: string, el: HT
|
|||
const disableFileTag = yaml?.disableFileTag || plugin.settings.defaultOverview.disableFileTag || false;
|
||||
const showEmptyFolders = yaml?.showEmptyFolders || plugin.settings.defaultOverview.showEmptyFolders || false;
|
||||
|
||||
el.parentElement?.classList.add('folder-overview-container');
|
||||
const root = el.createEl('div', { cls: 'folder-overview' });
|
||||
const titleEl = root.createEl('h1', { cls: 'folder-overview-title' });
|
||||
const ul = root.createEl('ul', { cls: 'folder-overview-list' });
|
||||
|
|
@ -58,7 +60,6 @@ export function createOverview(plugin: FolderNotesPlugin, source: string, el: HT
|
|||
if (!sourceFile) return;
|
||||
const sourceFolderPath = plugin.getFolderPathFromString(ctx.sourcePath);
|
||||
let sourceFolder: TFolder | undefined;
|
||||
|
||||
if (sourceFile.parent instanceof TFolder) {
|
||||
sourceFolder = sourceFile.parent;
|
||||
} else {
|
||||
|
|
@ -78,6 +79,17 @@ export function createOverview(plugin: FolderNotesPlugin, source: string, el: HT
|
|||
if (!includeTypes.includes('folder')) {
|
||||
files = getAllFiles(files, sourceFolderPath, depth);
|
||||
}
|
||||
if (files.length === 0) {
|
||||
// create button to edit the overview
|
||||
const editButton = root.createEl('button', { cls: 'folder-overview-edit-button' });
|
||||
editButton.innerText = 'Edit overview';
|
||||
editButton.addEventListener('click', (e) => {
|
||||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
new FolderOverviewSettings(plugin.app, plugin, parseYaml(source), ctx, el).open();
|
||||
}, { capture: true });
|
||||
}
|
||||
files = sortFiles(files, yaml, plugin);
|
||||
|
||||
if (style === 'grid') {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { App, Modal, Setting, TFolder } from 'obsidian';
|
||||
import { App, ButtonComponent, Modal, Setting, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { createFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getTemplatePlugins } from 'src/template';
|
||||
import { getExcludedFolder } from 'src/excludedFolder';
|
||||
export default class ConfirmationModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
@ -11,6 +13,19 @@ export default class ConfirmationModal extends Modal {
|
|||
this.app = app;
|
||||
}
|
||||
onOpen() {
|
||||
console.log(this.containerEl)
|
||||
this.modalEl.addClass('fn-confirmation-modal');
|
||||
let templateFolderPath: string;
|
||||
const { templateFolder, templaterPlugin } = getTemplatePlugins(this.plugin.app);
|
||||
if ((!templateFolder || templateFolder?.trim() === '') && !templaterPlugin) {
|
||||
templateFolderPath = '';
|
||||
}
|
||||
if (templaterPlugin) {
|
||||
templateFolderPath = templaterPlugin.plugin?.settings?.templates_folder as string;
|
||||
} else {
|
||||
templateFolderPath = templateFolder;
|
||||
}
|
||||
|
||||
const { contentEl } = this;
|
||||
contentEl.createEl('h2', { text: 'Create folder note for every folder' });
|
||||
const setting = new Setting(contentEl);
|
||||
|
|
@ -18,29 +33,33 @@ export default class ConfirmationModal extends Modal {
|
|||
setting.infoEl.createEl('p', { text: 'This feature will create a folder note for every folder in your vault.' });
|
||||
setting.infoEl.createEl('p', { text: 'Every folder that already has a folder note will be ignored.' });
|
||||
setting.infoEl.createEl('p', { text: 'Every excluded folder will be ignored.' });
|
||||
setting.infoEl.parentElement?.classList.add('fn-confirmation-modal');
|
||||
const button = setting.infoEl.createEl('button', { text: 'Create' });
|
||||
button.classList.add('mod-warning', 'fn-confirmation-modal-button');
|
||||
button.addEventListener('click', async () => {
|
||||
this.close();
|
||||
this.app.vault.getAllLoadedFiles().forEach(async (folder) => {
|
||||
if (folder instanceof TFolder) {
|
||||
const excludedFolder = this.plugin.settings.excludeFolders.find(
|
||||
(excludedFolder) => (excludedFolder.path === folder.path) ||
|
||||
(excludedFolder.path === folder.path?.slice(0, folder?.path.lastIndexOf('/') >= 0 ? folder.path?.lastIndexOf('/') : folder.path.length)
|
||||
&& excludedFolder.subFolders));
|
||||
if (excludedFolder) return;
|
||||
const path = folder.path + '/' + this.plugin.settings.folderNoteName.replace('{{folder_name}}', folder.name) + '.md';
|
||||
if (this.app.vault.getAbstractFileByPath(path)) return;
|
||||
await createFolderNote(this.plugin, folder.path, true);
|
||||
}
|
||||
new Setting(contentEl)
|
||||
.addButton((cb: ButtonComponent) => {
|
||||
cb.setButtonText('Create');
|
||||
cb.setCta();
|
||||
cb.buttonEl.focus();
|
||||
cb.onClick(async () => {
|
||||
this.close();
|
||||
const folders = this.app.vault.getAllLoadedFiles().filter((file) => file.parent instanceof TFolder);
|
||||
for (const folder of folders) {
|
||||
if (folder instanceof TFolder) {
|
||||
const excludedFolder = getExcludedFolder(this.plugin, folder.path);
|
||||
if (excludedFolder) continue;
|
||||
console.log(folder.path);
|
||||
if (folder.path === templateFolderPath) continue;
|
||||
const path = folder.path + '/' + this.plugin.settings.folderNoteName.replace('{{folder_name}}', folder.name) + '.md';
|
||||
if (this.app.vault.getAbstractFileByPath(path)) continue;
|
||||
await createFolderNote(this.plugin, folder.path, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
.addButton((cb: ButtonComponent) => {
|
||||
cb.setButtonText('Cancel');
|
||||
cb.onClick(async () => {
|
||||
this.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
button.focus();
|
||||
const cancelButton = setting.infoEl.createEl('button', { text: 'Cancel' });
|
||||
cancelButton.addEventListener('click', async () => {
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { TemplateSuggest } from './suggesters/templateSuggester';
|
|||
import { extractFolderName, getFolderNote } from './functions/folderNoteFunctions';
|
||||
import { addExcludeFolderListItem, ExcludedFolder, addExcludedFolder, ExcludePattern, addExcludePatternListItem } from './excludedFolder';
|
||||
import { FrontMatterTitlePluginHandler } from './events/frontMatterTitle';
|
||||
// import ConfirmationModal from "./modals/confirmCreation";
|
||||
import ConfirmationModal from "./modals/confirmCreation";
|
||||
import { yamlSettings } from './folderOverview';
|
||||
export interface FolderNotesSettings {
|
||||
syncFolderName: boolean;
|
||||
|
|
@ -447,10 +447,7 @@ export class SettingsTab extends PluginSettingTab {
|
|||
);
|
||||
}
|
||||
|
||||
// Due to an issue with templater it has been disabled for now
|
||||
// If you want to try it yourself make a pr
|
||||
// The issue was that it only used the first folder for all of the other folder notes
|
||||
/*
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Create folder note for every folder')
|
||||
.setDesc('Create a folder note for every folder in the vault')
|
||||
|
|
@ -458,10 +455,10 @@ export class SettingsTab extends PluginSettingTab {
|
|||
cb.setIcon('plus');
|
||||
cb.setTooltip('Create folder notes');
|
||||
cb.onClick(async () => {
|
||||
|
||||
new ConfirmationModal(this.app, this.plugin).open();
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
const manageExcluded = new Setting(containerEl)
|
||||
|
|
|
|||
|
|
@ -167,4 +167,9 @@
|
|||
flex: 1 1 auto;
|
||||
margin-right: 1.200rem;
|
||||
margin-bottom: 1.200rem;
|
||||
}
|
||||
}
|
||||
|
||||
.fn-confirmation-modal .setting-item {
|
||||
border-top: 0 !important;
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue