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
29b0a2d922
commit
6a2297e739
5 changed files with 383 additions and 383 deletions
|
|
@ -1,142 +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';
|
||||
// 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 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 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 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 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 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 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);
|
||||
});
|
||||
});
|
||||
// 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('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('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;
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
// settings.display();
|
||||
// });
|
||||
// });
|
||||
|
||||
setting.addButton((cb) => {
|
||||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete excluded folder');
|
||||
cb.onClick(() => {
|
||||
deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
// setting.addButton((cb) => {
|
||||
// cb.setIcon('trash-2');
|
||||
// cb.setTooltip('Delete excluded folder');
|
||||
// cb.onClick(() => {
|
||||
// deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
// setting.clear();
|
||||
// setting.settingEl.remove();
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,123 +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';
|
||||
// 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 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 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 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();
|
||||
});
|
||||
});
|
||||
// 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('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;
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
// 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();
|
||||
});
|
||||
});
|
||||
}
|
||||
// setting.addButton((cb) => {
|
||||
// cb.setIcon('trash-2');
|
||||
// cb.setTooltip('Delete pattern');
|
||||
// cb.onClick(() => {
|
||||
// deletePattern(plugin, pattern);
|
||||
// setting.clear();
|
||||
// setting.settingEl.remove();
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
|
@ -1,103 +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();
|
||||
})
|
||||
);
|
||||
// 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('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('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 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();
|
||||
})
|
||||
);
|
||||
// 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();
|
||||
})
|
||||
);
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
// }
|
||||
// onClose() {
|
||||
// const { contentEl } = this;
|
||||
// contentEl.empty();
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -1,46 +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() {
|
||||
// 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' });
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
// onClose() {
|
||||
// const { contentEl } = this;
|
||||
// contentEl.empty();
|
||||
// }
|
||||
// }
|
||||
|
|
@ -5,7 +5,7 @@ import { Setting } from 'obsidian';
|
|||
import { SettingsTab } from "./SettingsTab";
|
||||
import ExcludedFolderSettings from 'src/ExcludeFolders/modals/ExcludeFolderSettings';
|
||||
import PatternSettings from 'src/ExcludeFolders/modals/PatternSettings';
|
||||
import ExcludedFoldersWhitelist from 'src/ExcludeFolders/modals/WhitelistModal';
|
||||
// import ExcludedFoldersWhitelist from 'src/ExcludeFolders/modals/WhitelistModal';
|
||||
|
||||
export async function renderExcludeFolders(settingsTab: SettingsTab) {
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
|
|
|
|||
Loading…
Reference in a new issue