mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Fix excluded folders bug & style reload issues
This commit is contained in:
parent
63ee47ba7f
commit
29b0a2d922
27 changed files with 833 additions and 327 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "folder-notes",
|
||||
"name": "Folder notes",
|
||||
"version": "1.7.14",
|
||||
"version": "1.7.15",
|
||||
"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",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { App, TFolder, Menu, TAbstractFile, Notice, TFile, Editor, MarkdownView, Platform, stringifyYaml } from 'obsidian';
|
||||
import FolderNotesPlugin from './main';
|
||||
import { getFolderNote, createFolderNote, deleteFolderNote, turnIntoFolderNote, openFolderNote, extractFolderName } from './functions/folderNoteFunctions';
|
||||
import { ExcludedFolder } from './excludedFolder';
|
||||
import { ExcludedFolder } from './ExcludeFolders/ExcludeFolder';
|
||||
import { getFolderPathFromString } from './functions/utils';
|
||||
|
||||
export class Commands {
|
||||
|
|
|
|||
27
src/ExcludeFolders/ExcludeFolder.ts
Normal file
27
src/ExcludeFolders/ExcludeFolder.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import FolderNotesPlugin from '../main';
|
||||
export class ExcludedFolder {
|
||||
type: string;
|
||||
path: string;
|
||||
string: string;
|
||||
subFolders: boolean;
|
||||
disableSync: boolean;
|
||||
disableAutoCreate: boolean;
|
||||
disableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
position: number;
|
||||
excludeFromFolderOverview: boolean;
|
||||
hideInSettings: boolean;
|
||||
constructor(path: string, position: number, plugin: FolderNotesPlugin) {
|
||||
this.type = 'folder';
|
||||
this.path = path;
|
||||
this.subFolders = plugin.settings.excludeFolderDefaultSettings.subFolders;
|
||||
this.disableSync = plugin.settings.excludeFolderDefaultSettings.disableSync;
|
||||
this.disableAutoCreate = plugin.settings.excludeFolderDefaultSettings.disableAutoCreate;
|
||||
this.disableFolderNote = plugin.settings.excludeFolderDefaultSettings.disableFolderNote;
|
||||
this.enableCollapsing = plugin.settings.excludeFolderDefaultSettings.enableCollapsing;
|
||||
this.position = position;
|
||||
this.excludeFromFolderOverview = plugin.settings.excludeFolderDefaultSettings.excludeFromFolderOverview;
|
||||
this.string = '';
|
||||
this.hideInSettings = false;
|
||||
}
|
||||
}
|
||||
27
src/ExcludeFolders/ExcludePattern.ts
Normal file
27
src/ExcludeFolders/ExcludePattern.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import FolderNotesPlugin from '../main';
|
||||
export class ExcludePattern {
|
||||
type: string;
|
||||
string: string;
|
||||
path: string;
|
||||
position: number;
|
||||
subFolders: boolean;
|
||||
disableSync: boolean;
|
||||
disableAutoCreate: boolean;
|
||||
disableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
excludeFromFolderOverview: boolean;
|
||||
hideInSettings: boolean;
|
||||
constructor(pattern: string, position: number, plugin: FolderNotesPlugin) {
|
||||
this.type = 'pattern';
|
||||
this.string = pattern;
|
||||
this.position = position;
|
||||
this.subFolders = plugin.settings.excludePatternDefaultSettings.subFolders;
|
||||
this.disableSync = plugin.settings.excludePatternDefaultSettings.disableSync;
|
||||
this.disableAutoCreate = plugin.settings.excludePatternDefaultSettings.disableAutoCreate;
|
||||
this.disableFolderNote = plugin.settings.excludePatternDefaultSettings.disableFolderNote;
|
||||
this.enableCollapsing = plugin.settings.excludePatternDefaultSettings.enableCollapsing;
|
||||
this.excludeFromFolderOverview = plugin.settings.excludePatternDefaultSettings.excludeFromFolderOverview;
|
||||
this.path = '';
|
||||
this.hideInSettings = false;
|
||||
}
|
||||
}
|
||||
20
src/ExcludeFolders/WhitelistFolder.ts
Normal file
20
src/ExcludeFolders/WhitelistFolder.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import FolderNotesPlugin from '../main';
|
||||
export class WhitelistedFolder {
|
||||
type: string;
|
||||
path: string;
|
||||
string: string;
|
||||
subFolders: boolean;
|
||||
enableSync: boolean;
|
||||
enableAutoCreate: boolean;
|
||||
enabledFolderNote: boolean;
|
||||
disableCollapsing: boolean;
|
||||
allowAll: boolean;
|
||||
position: number;
|
||||
constructor(path: string, position: number, plugin: FolderNotesPlugin) {
|
||||
this.type = 'folder';
|
||||
this.path = path;
|
||||
this.subFolders = plugin.settings.excludeFolderDefaultSettings.subFolders;
|
||||
this.position = position;
|
||||
this.string = '';
|
||||
}
|
||||
}
|
||||
21
src/ExcludeFolders/WhitelistPattern.ts
Normal file
21
src/ExcludeFolders/WhitelistPattern.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import FolderNotesPlugin from '../main';
|
||||
export class WhitelistedPattern {
|
||||
type: string;
|
||||
string: string;
|
||||
path: string;
|
||||
position: number;
|
||||
subFolders: boolean;
|
||||
disableSync: boolean;
|
||||
disableAutoCreate: boolean;
|
||||
disableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
allowAll: boolean;
|
||||
hideInSettings: boolean;
|
||||
constructor(pattern: string, position: number, plugin: FolderNotesPlugin) {
|
||||
this.type = 'pattern';
|
||||
this.subFolders = plugin.settings.excludePatternDefaultSettings.subFolders;
|
||||
this.position = position;
|
||||
this.string = pattern;
|
||||
this.path = '';
|
||||
}
|
||||
}
|
||||
153
src/ExcludeFolders/functions/folderFunctions.ts
Normal file
153
src/ExcludeFolders/functions/folderFunctions.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
import FolderNotesPlugin from '../../main';
|
||||
import { getFolderNameFromPathString, getFolderPathFromString } from '../../functions/utils';
|
||||
import { ExcludedFolder } from '../ExcludeFolder';
|
||||
import { ExcludePattern } from '../ExcludePattern';
|
||||
import { Setting } from 'obsidian';
|
||||
import { FolderSuggest } from '../../suggesters/FolderSuggester';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import ExcludedFolderSettings from '../modals/ExcludeFolderSettings';
|
||||
import { updatePattern, getExcludedFolderByPattern, addExcludePatternListItem } from './patternFunctions';
|
||||
|
||||
export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) {
|
||||
console.log('get excluded folder', path);
|
||||
const folderName = getFolderNameFromPathString(path);
|
||||
const matchedPattern = getExcludedFolderByPattern(plugin, folderName);
|
||||
if (matchedPattern) { return matchedPattern; }
|
||||
console.log('test 3', path);
|
||||
console.log('test 4', folderName)
|
||||
const excludedFolder = getExcludedFolderByPath(plugin, path);
|
||||
if (excludedFolder?.path === '') { return; }
|
||||
return excludedFolder;
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.excludeFolders.find((excludedFolder) => {
|
||||
if (excludedFolder.path === path) { return true; }
|
||||
if (!excludedFolder.subFolders) { return false; }
|
||||
const excludedFolderPath = excludedFolder.path.includes('/') ? excludedFolder.path : excludedFolder.path + '/';
|
||||
let folderPath = getFolderPathFromString(path);
|
||||
folderPath = folderPath.includes('/') ? folderPath : folderPath + '/';
|
||||
|
||||
if (folderPath.includes('/') || folderPath.includes('\\')) {
|
||||
return folderPath.startsWith(excludedFolderPath) || folderPath === excludedFolderPath;
|
||||
} else {
|
||||
return folderPath === excludedFolderPath;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludedFolder) {
|
||||
plugin.settings.excludeFolders.push(excludedFolder);
|
||||
plugin.saveSettings(true);
|
||||
}
|
||||
|
||||
export function deleteExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludedFolder) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.path !== excludedFolder.path || folder.type === 'pattern');
|
||||
plugin.saveSettings(true);
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function updateExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludePattern, newExcludeFolder: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.path !== excludedFolder.path);
|
||||
addExcludedFolder(plugin, newExcludeFolder);
|
||||
}
|
||||
|
||||
export function resyncArray(plugin: FolderNotesPlugin) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.sort((a, b) => a.position - b.position);
|
||||
plugin.settings.excludeFolders.forEach((folder, index) => {
|
||||
folder.position = index;
|
||||
});
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
|
||||
export function addExcludeFolderListItem(settings: SettingsTab, containerEl: HTMLElement, excludedFolder: ExcludedFolder) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
new FolderSuggest(
|
||||
cb.inputEl,
|
||||
plugin
|
||||
);
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Folder path');
|
||||
cb.setValue(excludedFolder.path);
|
||||
cb.onChange((value) => {
|
||||
if (value.startsWith('{regex}') || value.includes('*')) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
const pattern = new ExcludePattern(value, plugin.settings.excludeFolders.length, plugin);
|
||||
addExcludedFolder(plugin, pattern);
|
||||
addExcludePatternListItem(settings, containerEl, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
}
|
||||
if (!plugin.app.vault.getAbstractFileByPath(value)) return;
|
||||
excludedFolder.path = value;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('edit');
|
||||
cb.setTooltip('Edit folder note');
|
||||
cb.onClick(() => {
|
||||
new ExcludedFolderSettings(plugin.app, plugin, excludedFolder).open();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('up-chevron-glyph');
|
||||
cb.setTooltip('Move up');
|
||||
cb.onClick(() => {
|
||||
if (excludedFolder.position === 0) { return; }
|
||||
excludedFolder.position -= 1;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find((folder) => folder.position === excludedFolder.position);
|
||||
if (oldExcludedFolder) {
|
||||
oldExcludedFolder.position += 1;
|
||||
if (oldExcludedFolder.type === 'pattern') {
|
||||
updatePattern(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('down-chevron-glyph');
|
||||
cb.setTooltip('Move down');
|
||||
cb.onClick(() => {
|
||||
if (excludedFolder.position === plugin.settings.excludeFolders.length - 1) {
|
||||
return;
|
||||
}
|
||||
excludedFolder.position += 1;
|
||||
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find((folder) => folder.position === excludedFolder.position);
|
||||
if (oldExcludedFolder) {
|
||||
oldExcludedFolder.position -= 1;
|
||||
if (oldExcludedFolder.type === 'pattern') {
|
||||
updatePattern(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
}
|
||||
}
|
||||
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete excluded folder');
|
||||
cb.onClick(() => {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
122
src/ExcludeFolders/functions/patternFunctions.ts
Normal file
122
src/ExcludeFolders/functions/patternFunctions.ts
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludePattern } from '../ExcludePattern';
|
||||
import { Setting } from 'obsidian';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { addExcludedFolder, resyncArray, updateExcludedFolder } from './folderFunctions';
|
||||
import PatternSettings from '../modals/PatternSettings';
|
||||
|
||||
export function updatePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern, newPattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.string !== pattern.string);
|
||||
addExcludedFolder(plugin, newPattern);
|
||||
}
|
||||
|
||||
export function deletePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.string !== pattern.string || folder.type === 'folder');
|
||||
plugin.saveSettings();
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPattern(plugin: FolderNotesPlugin, folderName: string) {
|
||||
return plugin.settings.excludeFolders.filter((s) => s.type == 'pattern').find((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludePatternListItem(settings: SettingsTab, containerEl: HTMLElement, pattern: ExcludePattern) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Pattern');
|
||||
cb.setValue(pattern.string);
|
||||
cb.onChange((value) => {
|
||||
if (plugin.settings.excludeFolders.find((folder) => folder.string === value)) { return; }
|
||||
pattern.string = value;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
});
|
||||
});
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('edit');
|
||||
cb.setTooltip('Edit pattern');
|
||||
cb.onClick(() => {
|
||||
new PatternSettings(plugin.app, plugin, pattern).open();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('up-chevron-glyph');
|
||||
cb.setTooltip('Move up');
|
||||
cb.onClick(() => {
|
||||
if (pattern.position === 0) { return; }
|
||||
pattern.position -= 1;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position += 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('down-chevron-glyph');
|
||||
cb.setTooltip('Move down');
|
||||
cb.onClick(() => {
|
||||
if (pattern.position === plugin.settings.excludeFolders.length - 1) {
|
||||
return;
|
||||
}
|
||||
pattern.position += 1;
|
||||
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position -= 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete pattern');
|
||||
cb.onClick(() => {
|
||||
deletePattern(plugin, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
142
src/ExcludeFolders/functions/whitelistFolderFunctions.ts
Normal file
142
src/ExcludeFolders/functions/whitelistFolderFunctions.ts
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
import FolderNotesPlugin from '../../main';
|
||||
import { getFolderNameFromPathString, getFolderPathFromString } from '../../functions/utils';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import { WhitelistedPattern } from '../WhitelistPattern';
|
||||
import { Setting } from 'obsidian';
|
||||
import { FolderSuggest } from '../../suggesters/FolderSuggester';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import WhitelistedFolderSettings from '../modals/WhitelistFolderSettings';
|
||||
import { updatePattern, getWhitelistedFolderByPattern, addWhitelistPatternListItem } from './patternFunctions';
|
||||
|
||||
export function getWhitelistedFolder(plugin: FolderNotesPlugin, path: string) {
|
||||
const folderName = getFolderNameFromPathString(path);
|
||||
const matchedPattern = getWhitelistedFolderByPattern(plugin, folderName);
|
||||
if (matchedPattern) { return matchedPattern; }
|
||||
const whitelistedFolder = getWhitelistedFolderByPath(plugin, path);
|
||||
if (whitelistedFolder?.path === '') { return; }
|
||||
return whitelistedFolder;
|
||||
}
|
||||
|
||||
export function getWhitelistedFolderByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.whitelistFolders.find((whitelistedFolder) => {
|
||||
if (whitelistedFolder.path === path) { return true; }
|
||||
if (!whitelistedFolder.subFolders) { return false; }
|
||||
return getFolderPathFromString(path).startsWith(whitelistedFolder.path);
|
||||
});
|
||||
}
|
||||
|
||||
export function addWhitelistedFolder(plugin: FolderNotesPlugin, whitelistedFolder: WhitelistedFolder) {
|
||||
plugin.settings.whitelistFolders.push(whitelistedFolder);
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
export function deleteWhitelistedFolder(plugin: FolderNotesPlugin, whitelistedFolder: WhitelistedFolder) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter((folder) => folder.path !== whitelistedFolder.path || folder.type === 'pattern');
|
||||
plugin.saveSettings();
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function updateWhitelistedFolder(plugin: FolderNotesPlugin, whitelistedFolder: WhitelistPattern, newWhitelistFolder: WhitelistPattern) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter((folder) => folder.path !== whitelistedFolder.path);
|
||||
addWhitelistedFolder(plugin, newWhitelistFolder);
|
||||
}
|
||||
|
||||
export function resyncArray(plugin: FolderNotesPlugin) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.sort((a, b) => a.position - b.position);
|
||||
plugin.settings.whitelistFolders.forEach((folder, index) => {
|
||||
folder.position = index;
|
||||
});
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
|
||||
export function addWhitelistFolderListItem(settings: SettingsTab, containerEl: HTMLElement, whitelistedFolder: WhitelistedFolder) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
new FolderSuggest(
|
||||
cb.inputEl,
|
||||
plugin
|
||||
);
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Folder path');
|
||||
cb.setValue(whitelistedFolder.path);
|
||||
cb.onChange((value) => {
|
||||
if (value.startsWith('{regex}') || value.includes('*')) {
|
||||
deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
const pattern = new WhitelistPattern(value, plugin.settings.whitelistFolders.length, plugin);
|
||||
addWhitelistedFolder(plugin, pattern);
|
||||
addWhitelistPatternListItem(settings, containerEl, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
}
|
||||
if (!plugin.app.vault.getAbstractFileByPath(value)) return;
|
||||
whitelistedFolder.path = value;
|
||||
updateWhitelistedFolder(plugin, whitelistedFolder, whitelistedFolder);
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('edit');
|
||||
cb.setTooltip('Edit folder note');
|
||||
cb.onClick(() => {
|
||||
new WhitelistedFolderSettings(plugin.app, plugin, whitelistedFolder).open();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('up-chevron-glyph');
|
||||
cb.setTooltip('Move up');
|
||||
cb.onClick(() => {
|
||||
if (whitelistedFolder.position === 0) { return; }
|
||||
whitelistedFolder.position -= 1;
|
||||
updateWhitelistedFolder(plugin, whitelistedFolder, whitelistedFolder);
|
||||
const oldWhitelistedFolder = plugin.settings.whitelistFolders.find((folder) => folder.position === whitelistedFolder.position);
|
||||
if (oldWhitelistedFolder) {
|
||||
oldWhitelistedFolder.position += 1;
|
||||
if (oldWhitelistedFolder.type === 'pattern') {
|
||||
updatePattern(plugin, oldWhitelistedFolder, oldWhitelistedFolder);
|
||||
} else {
|
||||
updateWhitelistedFolder(plugin, oldWhitelistedFolder, oldWhitelistedFolder);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('down-chevron-glyph');
|
||||
cb.setTooltip('Move down');
|
||||
cb.onClick(() => {
|
||||
if (whitelistedFolder.position === plugin.settings.whitelistFolders.length - 1) {
|
||||
return;
|
||||
}
|
||||
whitelistedFolder.position += 1;
|
||||
|
||||
updateWhitelistedFolder(plugin, whitelistedFolder, whitelistedFolder);
|
||||
const oldWhitelistedFolder = plugin.settings.whitelistFolders.find((folder) => folder.position === whitelistedFolder.position);
|
||||
if (oldWhitelistedFolder) {
|
||||
oldWhitelistedFolder.position -= 1;
|
||||
if (oldWhitelistedFolder.type === 'pattern') {
|
||||
updatePattern(plugin, oldWhitelistedFolder, oldWhitelistedFolder);
|
||||
} else {
|
||||
updateWhitelistedFolder(plugin, oldWhitelistedFolder, oldWhitelistedFolder);
|
||||
}
|
||||
}
|
||||
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete excluded folder');
|
||||
cb.onClick(() => {
|
||||
deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
123
src/ExcludeFolders/functions/whitelistPatternFunctions.ts
Normal file
123
src/ExcludeFolders/functions/whitelistPatternFunctions.ts
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludePattern } from '../ExcludePattern';
|
||||
import { Setting } from 'obsidian';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { addExcludedFolder, resyncArray, updateExcludedFolder } from './folderFunctions';
|
||||
import PatternSettings from '../modals/PatternSettings';
|
||||
import { WhitelistedPattern } from '../WhitelistPattern';
|
||||
|
||||
export function updatePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern, newPattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.string !== pattern.string);
|
||||
addExcludedFolder(plugin, newPattern);
|
||||
}
|
||||
|
||||
export function deletePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.string !== pattern.string || folder.type === 'folder');
|
||||
plugin.saveSettings();
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPattern(plugin: FolderNotesPlugin, folderName: string) {
|
||||
return plugin.settings.excludeFolders.filter((s) => s.type == 'pattern').find((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludePatternListItem(settings: SettingsTab, containerEl: HTMLElement, pattern: WhitelistedPattern) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Pattern');
|
||||
cb.setValue(pattern.string);
|
||||
cb.onChange((value) => {
|
||||
if (plugin.settings.excludeFolders.find((folder) => folder.string === value)) { return; }
|
||||
pattern.string = value;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
});
|
||||
});
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('edit');
|
||||
cb.setTooltip('Edit pattern');
|
||||
cb.onClick(() => {
|
||||
new PatternSettings(plugin.app, plugin, pattern).open();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('up-chevron-glyph');
|
||||
cb.setTooltip('Move up');
|
||||
cb.onClick(() => {
|
||||
if (pattern.position === 0) { return; }
|
||||
pattern.position -= 1;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position += 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('down-chevron-glyph');
|
||||
cb.setTooltip('Move down');
|
||||
cb.onClick(() => {
|
||||
if (pattern.position === plugin.settings.excludeFolders.length - 1) {
|
||||
return;
|
||||
}
|
||||
pattern.position += 1;
|
||||
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position -= 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete pattern');
|
||||
cb.onClick(() => {
|
||||
deletePattern(plugin, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { ExcludedFolder } from 'src/excludedFolder';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
export default class ExcludedFolderSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
@ -26,7 +26,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.setValue(this.excludedFolder.subFolders)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.subFolders = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(true);
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.setValue(this.excludedFolder.disableFolderNote)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.disableFolderNote = value;
|
||||
await this.plugin.saveSettings();
|
||||
await this.plugin.saveSettings(true);
|
||||
this.display();
|
||||
})
|
||||
);
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { ExcludePattern } from 'src/excludedFolder';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
|
||||
|
||||
export default class PatternSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
103
src/ExcludeFolders/modals/WhitelistFolderSettings.ts
Normal file
103
src/ExcludeFolders/modals/WhitelistFolderSettings.ts
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
export default class ExcludedFolderSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
excludedFolder: WhitelistedFolder;
|
||||
constructor(app: App, plugin: FolderNotesPlugin, excludedFolder: WhitelistedFolder) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.app = app;
|
||||
this.excludedFolder = excludedFolder;
|
||||
}
|
||||
onOpen() {
|
||||
this.display();
|
||||
}
|
||||
display() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
contentEl.createEl('h2', { text: 'Excluded folder settings' });
|
||||
new Setting(contentEl)
|
||||
.setName('Include subfolders')
|
||||
.setDesc('Choose if the subfolders of the folder should also be whitelisted')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.subFolders)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.subFolders = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Disable folder name sync')
|
||||
.setDesc('Choose if the folder note should be renamed when the folder name is changed')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.disableSync)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.disableSync = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Don\'t show folder in folder overview')
|
||||
.setDesc('Choose if the folder should be shown in the folder overview')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.excludeFromFolderOverview)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.excludeFromFolderOverview = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Disable auto creation of folder notes in this folder')
|
||||
.setDesc('Choose if a folder note should be created when a new folder is created')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.disableAutoCreate)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.disableAutoCreate = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Disable open folder note')
|
||||
.setDesc('Choose if the folder note should be opened when the folder is opened')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.disableFolderNote)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.disableFolderNote = value;
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
})
|
||||
);
|
||||
|
||||
if (!this.excludedFolder.disableFolderNote) {
|
||||
new Setting(contentEl)
|
||||
.setName('Collapse folder when opening folder note')
|
||||
.setDesc('Choose if the folder should be collapsed when the folder note is opened')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.enableCollapsing)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.enableCollapsing = value;
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
46
src/ExcludeFolders/modals/WhitelistModal.ts
Normal file
46
src/ExcludeFolders/modals/WhitelistModal.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { App, ButtonComponent, Modal, Setting, TFolder, Notice } from 'obsidian';
|
||||
import { SettingsTab } from 'src/settings/SettingsTab';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
export default class ExcludedFoldersWhitelist extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
settingsTab: SettingsTab;
|
||||
constructor(app: App, plugin: FolderNotesPlugin) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.settingsTab = plugin.settingsTab
|
||||
}
|
||||
onOpen() {
|
||||
|
||||
const { contentEl } = this;
|
||||
contentEl.createEl('h2', { text: 'Manage whitelisted folders' });
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Add excluded folder')
|
||||
.setClass('add-exclude-folder-item')
|
||||
.addButton((cb) => {
|
||||
cb.setIcon('plus');
|
||||
cb.setClass('add-exclude-folder');
|
||||
cb.setTooltip('Add whitelisted folder');
|
||||
cb.onClick(() => {
|
||||
const whitelistedFolder = new WhitelistedFolder('', this.plugin.settings.whitelistFolders.length, this.plugin);
|
||||
addWhitelistFolderListItem(this.plugin.settingsTab, contentEl, whitelistedFolder);
|
||||
addWhitelistedFolder(this.plugin, whitelistedFolder);
|
||||
this.settingsTab.display();
|
||||
});
|
||||
});
|
||||
this.plugin.settings.whitelistFolders.sort((a, b) => a.position - b.position).forEach((whitelistedFolder) => {
|
||||
if (whitelistedFolder.string?.trim() !== '' && whitelistedFolder.path?.trim() === '') {
|
||||
addWhitelistPatternListItem(this.settingsTab, contentEl, whitelistedFolder);
|
||||
} else {
|
||||
addExcludeFolderListItem(this.settingsTab, contentEl, whitelistedFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
0
src/ExcludeFolders/modals/WhitelistPatternSettings.ts
Normal file
0
src/ExcludeFolders/modals/WhitelistPatternSettings.ts
Normal file
|
|
@ -1,7 +1,7 @@
|
|||
import { Keymap } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { openFolderNote, createFolderNote, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getExcludedFolder } from 'src/excludedFolder';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { addCSSClassToTitleEL, removeCSSClassFromEL } from 'src/functions/styleFunctions';
|
||||
|
||||
export async function handleViewHeaderClick(event: MouseEvent, plugin: FolderNotesPlugin) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { TAbstractFile, TFolder, TFile } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { createFolderNote, getFolder, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getExcludedFolder } from 'src/excludedFolder';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
|
||||
export function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { TFile, TFolder, TAbstractFile, Notice } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { extractFolderName, getFolderNote, getFolderNoteFolder } from '../functions/folderNoteFunctions';
|
||||
import { getExcludedFolder, ExcludedFolder, addExcludedFolder, updateExcludedFolder, deleteExcludedFolder } from '../excludedFolder';
|
||||
import { getExcludedFolder, addExcludedFolder, updateExcludedFolder, deleteExcludedFolder } from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
import { getFolderPathFromString, removeExtension, getFileNameFromPathString } from 'src/functions/utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,303 +0,0 @@
|
|||
import { Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from './main';
|
||||
import ExcludedFolderSettings from './modals/ExcludeFolderSettings';
|
||||
import { FolderSuggest } from './suggesters/FolderSuggester';
|
||||
import { SettingsTab } from './settings/SettingsTab';
|
||||
import PatternSettings from './modals/PatternSettings';
|
||||
import { getFolderNameFromPathString, getFolderPathFromString } from './functions/utils';
|
||||
|
||||
export class ExcludedFolder {
|
||||
type: string;
|
||||
path: string;
|
||||
string: string;
|
||||
subFolders: boolean;
|
||||
disableSync: boolean;
|
||||
disableAutoCreate: boolean;
|
||||
disableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
position: number;
|
||||
excludeFromFolderOverview: boolean;
|
||||
constructor(path: string, position: number, plugin: FolderNotesPlugin) {
|
||||
this.type = 'folder';
|
||||
this.path = path;
|
||||
this.subFolders = plugin.settings.excludeFolderDefaultSettings.subFolders;
|
||||
this.disableSync = plugin.settings.excludeFolderDefaultSettings.disableSync;
|
||||
this.disableAutoCreate = plugin.settings.excludeFolderDefaultSettings.disableAutoCreate;
|
||||
this.disableFolderNote = plugin.settings.excludeFolderDefaultSettings.disableFolderNote;
|
||||
this.enableCollapsing = plugin.settings.excludeFolderDefaultSettings.enableCollapsing;
|
||||
this.position = position;
|
||||
this.excludeFromFolderOverview = plugin.settings.excludeFolderDefaultSettings.excludeFromFolderOverview;
|
||||
this.string = '';
|
||||
}
|
||||
}
|
||||
|
||||
export class ExcludePattern {
|
||||
type: string;
|
||||
string: string;
|
||||
path: string;
|
||||
position: number;
|
||||
subFolders: boolean;
|
||||
disableSync: boolean;
|
||||
disableAutoCreate: boolean;
|
||||
disableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
excludeFromFolderOverview: boolean;
|
||||
constructor(pattern: string, position: number, plugin: FolderNotesPlugin) {
|
||||
this.type = 'pattern';
|
||||
this.string = pattern;
|
||||
this.position = position;
|
||||
this.subFolders = plugin.settings.excludePatternDefaultSettings.subFolders;
|
||||
this.disableSync = plugin.settings.excludePatternDefaultSettings.disableSync;
|
||||
this.disableAutoCreate = plugin.settings.excludePatternDefaultSettings.disableAutoCreate;
|
||||
this.disableFolderNote = plugin.settings.excludePatternDefaultSettings.disableFolderNote;
|
||||
this.enableCollapsing = plugin.settings.excludePatternDefaultSettings.enableCollapsing;
|
||||
this.excludeFromFolderOverview = plugin.settings.excludePatternDefaultSettings.excludeFromFolderOverview;
|
||||
this.path = '';
|
||||
}
|
||||
}
|
||||
|
||||
export function getExcludedFolder(plugin: FolderNotesPlugin, path: string) {
|
||||
const folderName = getFolderNameFromPathString(path);
|
||||
const matchedPattern = getExcludedFolderByPattern(plugin, folderName);
|
||||
if (matchedPattern) { return matchedPattern; }
|
||||
const excludedFolder = getExcludedFolderByPath(plugin, path);
|
||||
if (excludedFolder?.path === '') { return; }
|
||||
return excludedFolder;
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPattern(plugin: FolderNotesPlugin, folderName: string) {
|
||||
return plugin.settings.excludeFolders.filter((s) => s.type == 'pattern').find((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.excludeFolders.find((excludedFolder) => {
|
||||
if (excludedFolder.path === path) { return true; }
|
||||
if (!excludedFolder.subFolders) { return false; }
|
||||
return getFolderPathFromString(path).startsWith(excludedFolder.path);
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludedFolder) {
|
||||
plugin.settings.excludeFolders.push(excludedFolder);
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
export function deleteExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludedFolder) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.path !== excludedFolder.path || folder.type === 'pattern');
|
||||
plugin.saveSettings();
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function deletePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.string !== pattern.string || folder.type === 'folder');
|
||||
plugin.saveSettings();
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function updateExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludePattern, newExcludeFolder: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.path !== excludedFolder.path);
|
||||
addExcludedFolder(plugin, newExcludeFolder);
|
||||
}
|
||||
|
||||
export function updatePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern, newPattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.string !== pattern.string);
|
||||
addExcludedFolder(plugin, newPattern);
|
||||
}
|
||||
|
||||
function resyncArray(plugin: FolderNotesPlugin) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.sort((a, b) => a.position - b.position);
|
||||
plugin.settings.excludeFolders.forEach((folder, index) => {
|
||||
folder.position = index;
|
||||
});
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
export function addExcludePatternListItem(settings: SettingsTab, containerEl: HTMLElement, pattern: ExcludePattern) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Pattern');
|
||||
cb.setValue(pattern.string);
|
||||
cb.onChange((value) => {
|
||||
if (plugin.settings.excludeFolders.find((folder) => folder.string === value)) { return; }
|
||||
pattern.string = value;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
});
|
||||
});
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('edit');
|
||||
cb.setTooltip('Edit pattern');
|
||||
cb.onClick(() => {
|
||||
new PatternSettings(plugin.app, plugin, pattern).open();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('up-chevron-glyph');
|
||||
cb.setTooltip('Move up');
|
||||
cb.onClick(() => {
|
||||
if (pattern.position === 0) { return; }
|
||||
pattern.position -= 1;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position += 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('down-chevron-glyph');
|
||||
cb.setTooltip('Move down');
|
||||
cb.onClick(() => {
|
||||
if (pattern.position === plugin.settings.excludeFolders.length - 1) {
|
||||
return;
|
||||
}
|
||||
pattern.position += 1;
|
||||
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position -= 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete pattern');
|
||||
cb.onClick(() => {
|
||||
deletePattern(plugin, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludeFolderListItem(settings: SettingsTab, containerEl: HTMLElement, excludedFolder: ExcludedFolder) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
new FolderSuggest(
|
||||
cb.inputEl,
|
||||
plugin
|
||||
);
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Folder path');
|
||||
cb.setValue(excludedFolder.path);
|
||||
cb.onChange((value) => {
|
||||
if (value.startsWith('{regex}') || value.includes('*')) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
const pattern = new ExcludePattern(value, plugin.settings.excludeFolders.length, plugin);
|
||||
addExcludedFolder(plugin, pattern);
|
||||
addExcludePatternListItem(settings, containerEl, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
}
|
||||
if (!plugin.app.vault.getAbstractFileByPath(value)) return;
|
||||
excludedFolder.path = value;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('edit');
|
||||
cb.setTooltip('Edit folder note');
|
||||
cb.onClick(() => {
|
||||
new ExcludedFolderSettings(plugin.app, plugin, excludedFolder).open();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('up-chevron-glyph');
|
||||
cb.setTooltip('Move up');
|
||||
cb.onClick(() => {
|
||||
if (excludedFolder.position === 0) { return; }
|
||||
excludedFolder.position -= 1;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find((folder) => folder.position === excludedFolder.position);
|
||||
if (oldExcludedFolder) {
|
||||
oldExcludedFolder.position += 1;
|
||||
if (oldExcludedFolder.type === 'pattern') {
|
||||
updatePattern(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
}
|
||||
}
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('down-chevron-glyph');
|
||||
cb.setTooltip('Move down');
|
||||
cb.onClick(() => {
|
||||
if (excludedFolder.position === plugin.settings.excludeFolders.length - 1) {
|
||||
return;
|
||||
}
|
||||
excludedFolder.position += 1;
|
||||
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find((folder) => folder.position === excludedFolder.position);
|
||||
if (oldExcludedFolder) {
|
||||
oldExcludedFolder.position -= 1;
|
||||
if (oldExcludedFolder.type === 'pattern') {
|
||||
updatePattern(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldExcludedFolder, oldExcludedFolder);
|
||||
}
|
||||
}
|
||||
|
||||
settings.display();
|
||||
});
|
||||
});
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete excluded folder');
|
||||
cb.onClick(() => {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
import { MarkdownPostProcessorContext, parseYaml, TAbstractFile, TFolder, TFile, stringifyYaml, Notice } from 'obsidian';
|
||||
import { extractFolderName, getFolderNote } from '../functions/folderNoteFunctions';
|
||||
import { getFolderNote } from '../functions/folderNoteFunctions';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { FolderOverviewSettings } from './ModalSettings';
|
||||
import { getExcludedFolder } from '../excludedFolder';
|
||||
import { getExcludedFolder } from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { getFolderPathFromString } from '../functions/utils';
|
||||
import { getEl } from 'src/functions/styleFunctions';
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ import ExistingFolderNoteModal from '../modals/ExistingNote';
|
|||
import { applyTemplate } from '../template';
|
||||
import { TFolder, TFile, TAbstractFile, Keymap } from 'obsidian';
|
||||
import DeleteConfirmationModal from '../modals/DeleteConfirmation';
|
||||
import { addExcludedFolder, deleteExcludedFolder, getExcludedFolder, ExcludedFolder, updateExcludedFolder } from '../excludedFolder';
|
||||
import { addExcludedFolder, deleteExcludedFolder, getExcludedFolder, updateExcludedFolder } from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from '../ExcludeFolders/ExcludeFolder';
|
||||
import { openExcalidrawView } from './excalidraw';
|
||||
import { AskForExtensionModal } from 'src/modals/AskForExtension';
|
||||
import { getEl, addCSSClassToTitleEL, removeCSSClassFromEL } from 'src/functions/styleFunctions';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { TFile, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { getExcludedFolder } from 'src/excludedFolder';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getFileExplorer } from './utils';
|
||||
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@ export function getFileExplorer() {
|
|||
|
||||
export function getFileExplorerView() {
|
||||
return this.getFileExplorer().view;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -260,6 +260,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
delete data.allowWhitespaceCollapsing;
|
||||
}
|
||||
}
|
||||
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, data);
|
||||
if (!data) { return; }
|
||||
const overview = (data as any).defaultOverview;
|
||||
|
|
@ -267,10 +268,10 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
this.settings.defaultOverview = Object.assign({}, DEFAULT_SETTINGS.defaultOverview, overview);
|
||||
}
|
||||
|
||||
async saveSettings() {
|
||||
async saveSettings(reloadStyles?: boolean) {
|
||||
await this.saveData(this.settings);
|
||||
// cleanup any css if we need too
|
||||
if (!this.settingsOpened) {
|
||||
if (!this.settingsOpened || reloadStyles === true) {
|
||||
loadFileClasses(true, this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { App, ButtonComponent, Modal, Setting, TFolder, Notice } from 'obsidian'
|
|||
import FolderNotesPlugin from '../main';
|
||||
import { createFolderNote, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getTemplatePlugins } from 'src/template';
|
||||
import { getExcludedFolder } from 'src/excludedFolder';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
export default class ConfirmationModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import { addExcludeFolderListItem, ExcludedFolder, addExcludedFolder, ExcludePattern, addExcludePatternListItem } from '../excludedFolder';
|
||||
import { addExcludeFolderListItem, addExcludedFolder} from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { addExcludePatternListItem } from 'src/ExcludeFolders/functions/patternFunctions';
|
||||
import { Setting } from 'obsidian';
|
||||
import { SettingsTab } from "./SettingsTab";
|
||||
import ExcludedFolderSettings from 'src/modals/ExcludeFolderSettings';
|
||||
import PatternSettings from 'src/modals/PatternSettings';
|
||||
|
||||
import ExcludedFolderSettings from 'src/ExcludeFolders/modals/ExcludeFolderSettings';
|
||||
import PatternSettings from 'src/ExcludeFolders/modals/PatternSettings';
|
||||
import ExcludedFoldersWhitelist from 'src/ExcludeFolders/modals/WhitelistModal';
|
||||
|
||||
export async function renderExcludeFolders(settingsTab: SettingsTab) {
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
|
|
@ -27,6 +29,18 @@ export async function renderExcludeFolders(settingsTab: SettingsTab) {
|
|||
manageExcluded.infoEl.appendText('If you want to switch to a folder path delete the pattern first.');
|
||||
manageExcluded.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
// ***Soon***
|
||||
// new Setting(containerEl)
|
||||
// .setName('Whitelisted folders')
|
||||
// .setDesc('Folders that will override the excluded folders/patterns')
|
||||
// .addButton((cb) => {
|
||||
// cb.setButtonText('Manage')
|
||||
// cb.setCta()
|
||||
// cb.onClick(async () => {
|
||||
// new ExcludedFoldersWhitelist(settingsTab.app, settingsTab.plugin).open();
|
||||
// })
|
||||
// })
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Exclude folder default settings')
|
||||
.addButton((cb) => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { App, Notice, PluginSettingTab, TFile, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { ExcludedFolder, ExcludePattern } from '../excludedFolder';
|
||||
import { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { getFolderNote } from '../functions/folderNoteFunctions';
|
||||
import { yamlSettings } from '../folderOverview/FolderOverview';
|
||||
import { renderGeneral } from './GeneralSettings';
|
||||
|
|
@ -9,6 +10,8 @@ import { renderPath } from './PathSettings';
|
|||
import { renderFolderOverview } from './FolderOverviewSettings';
|
||||
import { renderExcludeFolders } from './ExcludedFoldersSettings';
|
||||
import { getFolderPathFromString } from '../functions/utils';
|
||||
import { WhitelistedFolder } from 'src/ExcludeFolders/WhitelistFolder';
|
||||
import { WhitelistedPattern } from 'src/ExcludeFolders/WhitelistPattern';
|
||||
|
||||
export interface FolderNotesSettings {
|
||||
syncFolderName: boolean;
|
||||
|
|
@ -19,6 +22,7 @@ export interface FolderNotesSettings {
|
|||
autoCreate: boolean;
|
||||
enableCollapsing: boolean;
|
||||
excludeFolders: (ExcludePattern | ExcludedFolder)[];
|
||||
whitelistFolders: (WhitelistedFolder | WhitelistedPattern)[];
|
||||
showDeleteConfirmation: boolean;
|
||||
showRenameConfirmation: boolean;
|
||||
underlineFolder: boolean;
|
||||
|
|
@ -66,6 +70,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
autoCreate: false,
|
||||
enableCollapsing: false,
|
||||
excludeFolders: [],
|
||||
whitelistFolders: [],
|
||||
showDeleteConfirmation: true,
|
||||
underlineFolder: true,
|
||||
stopWhitespaceCollapsing: true,
|
||||
|
|
@ -124,6 +129,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
position: 0,
|
||||
excludeFromFolderOverview: false,
|
||||
string: '',
|
||||
hideInSettings: false,
|
||||
},
|
||||
excludePatternDefaultSettings: {
|
||||
type: 'pattern',
|
||||
|
|
@ -136,6 +142,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
position: 0,
|
||||
excludeFromFolderOverview: false,
|
||||
string: '',
|
||||
hideInSettings: false,
|
||||
},
|
||||
hideCollapsingIcon: false,
|
||||
tabManagerEnabled: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue