mirror of
https://github.com/felvesthe/Note-Locker.git
synced 2026-07-22 05:44:06 +00:00
Initial implementation of folder lock feature
* There are several other improvements Signed-off-by: Felvesthe <23108389+Felvesthe@users.noreply.github.com>
This commit is contained in:
parent
4b27d16d25
commit
98875376b9
5 changed files with 226 additions and 85 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "note-locker",
|
"name": "note-locker",
|
||||||
"version": "1.0.0",
|
"version": "1.2.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "note-locker",
|
"name": "note-locker",
|
||||||
"version": "1.0.0",
|
"version": "1.2.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^16.11.6",
|
"@types/node": "^16.11.6",
|
||||||
|
|
|
||||||
110
src/main.ts
110
src/main.ts
|
|
@ -71,7 +71,7 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
);
|
);
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.workspace.on("editor-menu",(menu, _, view) =>
|
this.app.workspace.on("editor-menu", (menu, _, view) =>
|
||||||
view.file && this.addLockMenuItem(menu, view.file.path)
|
view.file && this.addLockMenuItem(menu, view.file.path)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -85,12 +85,25 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
|
|
||||||
this.registerEvent(
|
this.registerEvent(
|
||||||
this.app.vault.on("rename", async (file, oldPath) => {
|
this.app.vault.on("rename", async (file, oldPath) => {
|
||||||
|
let settingsChanged = false;
|
||||||
|
|
||||||
|
// Handle locked notes
|
||||||
if (this.settings.lockedNotes.delete(oldPath)) {
|
if (this.settings.lockedNotes.delete(oldPath)) {
|
||||||
if (!this.settings.lockedNotes.has(file.path)) {
|
if (!this.settings.lockedNotes.has(file.path)) {
|
||||||
this.settings.lockedNotes.add(file.path);
|
this.settings.lockedNotes.add(file.path);
|
||||||
} else {
|
settingsChanged = true;
|
||||||
new Notice(`⚠️ Lock skipped: "${file.name}" was already locked`);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle locked folders
|
||||||
|
if (this.settings.lockedFolders.delete(oldPath)) {
|
||||||
|
if (!this.settings.lockedFolders.has(file.path)) {
|
||||||
|
this.settings.lockedFolders.add(file.path);
|
||||||
|
settingsChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settingsChanged) {
|
||||||
await this.saveSettings();
|
await this.saveSettings();
|
||||||
this.fileExplorerUI.updateFileExplorerIcons();
|
this.fileExplorerUI.updateFileExplorerIcons();
|
||||||
}
|
}
|
||||||
|
|
@ -117,17 +130,69 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
.forEach((leaf) => this.updateLeafMode(leaf));
|
.forEach((leaf) => this.updateLeafMode(leaf));
|
||||||
}
|
}
|
||||||
|
|
||||||
private addLockMenuItem(menu: Menu, filePath: string) {
|
private addLockMenuItem(menu: Menu, path: string) {
|
||||||
const isNote = filePath.endsWith('.md');
|
if (this.isParentFolderLocked(path)) {
|
||||||
if (!isNote) return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const isLocked = this.settings.lockedNotes.has(filePath);
|
const file = this.app.vault.getAbstractFileByPath(path);
|
||||||
menu.addItem((item) =>
|
|
||||||
item
|
if (file instanceof TFile && file.extension === 'md') {
|
||||||
.setTitle(isLocked ? "Unlock" : "Lock")
|
const isLocked = this.settings.lockedNotes.has(path);
|
||||||
.setIcon(isLocked ? "unlock" : "lock")
|
menu.addItem((item) =>
|
||||||
.onClick(() => this.toggleNoteLock(filePath))
|
item
|
||||||
);
|
.setTitle(isLocked ? "Unlock" : "Lock")
|
||||||
|
.setIcon(isLocked ? "unlock" : "lock")
|
||||||
|
.onClick(() => this.toggleNoteLock(path))
|
||||||
|
);
|
||||||
|
} else if (file && !(file instanceof TFile)) {
|
||||||
|
const isLocked = this.settings.lockedFolders.has(path);
|
||||||
|
menu.addItem((item) =>
|
||||||
|
item
|
||||||
|
.setTitle(isLocked ? "Unlock all notes in folder" : "Lock all notes in folder")
|
||||||
|
.setIcon(isLocked ? "unlock" : "lock")
|
||||||
|
.onClick(() => this.toggleFolderLock(path))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private isParentFolderLocked(path: string): boolean {
|
||||||
|
let currentPath = path;
|
||||||
|
while (currentPath.includes("/")) {
|
||||||
|
currentPath = currentPath.substring(0, currentPath.lastIndexOf("/"));
|
||||||
|
if (this.settings.lockedFolders.has(currentPath)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async toggleFolderLock(folderPath: string) {
|
||||||
|
const isLocked = this.settings.lockedFolders.has(folderPath);
|
||||||
|
|
||||||
|
isLocked
|
||||||
|
? this.settings.lockedFolders.delete(folderPath)
|
||||||
|
: this.settings.lockedFolders.add(folderPath);
|
||||||
|
|
||||||
|
await this.saveSettings();
|
||||||
|
|
||||||
|
new Notice(`${isLocked ? '🔓 Unlocked' : '🔒 Locked'} folder: ${folderPath}`);
|
||||||
|
|
||||||
|
this.updateAllNotesInFolder(folderPath);
|
||||||
|
this.statusBarUI.updateStatusBarButton();
|
||||||
|
this.fileExplorerUI.updateFileExplorerIcons();
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateAllNotesInFolder(folderPath: string) {
|
||||||
|
this.app.workspace
|
||||||
|
.getLeavesOfType("markdown")
|
||||||
|
.forEach((leaf) => {
|
||||||
|
if (leaf.view instanceof MarkdownView && leaf.view.file) {
|
||||||
|
if (leaf.view.file.path.startsWith(folderPath + "/")) {
|
||||||
|
this.updateLeafMode(leaf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async toggleNoteLock(notePath: string) {
|
async toggleNoteLock(notePath: string) {
|
||||||
|
|
@ -180,12 +245,25 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
return view instanceof MarkdownView && view.file?.path === notePath;
|
return view instanceof MarkdownView && view.file?.path === notePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isPathLocked(path: string): boolean {
|
||||||
|
if (this.settings.lockedNotes.has(path)) return true;
|
||||||
|
|
||||||
|
let currentPath = path;
|
||||||
|
while (currentPath.includes("/")) {
|
||||||
|
currentPath = currentPath.substring(0, currentPath.lastIndexOf("/"));
|
||||||
|
if (this.settings.lockedFolders.has(currentPath)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private updateLeafMode(leaf: WorkspaceLeaf | null) {
|
private updateLeafMode(leaf: WorkspaceLeaf | null) {
|
||||||
if (!leaf || !(leaf.view instanceof MarkdownView)) return;
|
if (!leaf || !(leaf.view instanceof MarkdownView)) return;
|
||||||
|
|
||||||
const { view } = leaf;
|
const { view } = leaf;
|
||||||
const targetMode =
|
const targetMode =
|
||||||
view.file && this.settings.lockedNotes.has(view.file.path)
|
view.file && this.isPathLocked(view.file.path)
|
||||||
? "preview"
|
? "preview"
|
||||||
: "source";
|
: "source";
|
||||||
|
|
||||||
|
|
@ -203,7 +281,8 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
this.settings = {
|
this.settings = {
|
||||||
...DEFAULT_SETTINGS,
|
...DEFAULT_SETTINGS,
|
||||||
...loaded,
|
...loaded,
|
||||||
lockedNotes: new Set(loaded.lockedNotes || [])
|
lockedNotes: new Set(loaded.lockedNotes || []),
|
||||||
|
lockedFolders: new Set(loaded.lockedFolders || [])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -212,6 +291,7 @@ export default class NoteLockerPlugin extends Plugin {
|
||||||
await this.saveData({
|
await this.saveData({
|
||||||
...this.settings,
|
...this.settings,
|
||||||
lockedNotes: Array.from(this.settings.lockedNotes),
|
lockedNotes: Array.from(this.settings.lockedNotes),
|
||||||
|
lockedFolders: Array.from(this.settings.lockedFolders),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
export interface NoteLockerSettings {
|
export interface NoteLockerSettings {
|
||||||
lockedNotes: Set<string>;
|
lockedNotes: Set<string>;
|
||||||
|
lockedFolders: Set<string>;
|
||||||
mobileNotificationMaxLength: number;
|
mobileNotificationMaxLength: number;
|
||||||
desktopNotificationMaxLength: number;
|
desktopNotificationMaxLength: number;
|
||||||
showFileExplorerIcons: boolean;
|
showFileExplorerIcons: boolean;
|
||||||
|
|
@ -9,6 +10,7 @@ export interface NoteLockerSettings {
|
||||||
|
|
||||||
export const DEFAULT_SETTINGS: NoteLockerSettings = {
|
export const DEFAULT_SETTINGS: NoteLockerSettings = {
|
||||||
lockedNotes: new Set(),
|
lockedNotes: new Set(),
|
||||||
|
lockedFolders: new Set(),
|
||||||
mobileNotificationMaxLength: 18,
|
mobileNotificationMaxLength: 18,
|
||||||
desktopNotificationMaxLength: 22,
|
desktopNotificationMaxLength: 22,
|
||||||
showFileExplorerIcons: true,
|
showFileExplorerIcons: true,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import {App, Platform, PluginSettingTab, Setting} from "obsidian";
|
import { App, Platform, PluginSettingTab, Setting } from "obsidian";
|
||||||
import type NoteLockerPlugin from "./main";
|
import type NoteLockerPlugin from "./main";
|
||||||
|
|
||||||
export class NoteLockerSettingTab extends PluginSettingTab {
|
export class NoteLockerSettingTab extends PluginSettingTab {
|
||||||
|
|
@ -80,10 +80,10 @@ export class NoteLockerSettingTab extends PluginSettingTab {
|
||||||
});
|
});
|
||||||
hotkeyInfo.style.fontStyle = 'italic';
|
hotkeyInfo.style.fontStyle = 'italic';
|
||||||
|
|
||||||
containerEl.createEl('h3', { text: 'Locked Notes' });
|
containerEl.createEl('h3', { text: 'Locked Notes & Folders' });
|
||||||
const lockedNotesCount = this.plugin.settings.lockedNotes.size;
|
const lockedNotesCount = this.plugin.settings.lockedNotes.size;
|
||||||
containerEl.createEl('p', {
|
containerEl.createEl('p', {
|
||||||
text: `You currently have ${lockedNotesCount} locked note${lockedNotesCount !== 1 ? 's' : ''}.`
|
text: `You currently have ${lockedNotesCount} locked note${lockedNotesCount !== 1 ? 's' : ''} and ${this.plugin.settings.lockedFolders.size} locked folder${this.plugin.settings.lockedFolders.size !== 1 ? 's' : ''}.`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,21 +15,20 @@ export class FileExplorerUI {
|
||||||
styleEl.id = 'note-locker-styles';
|
styleEl.id = 'note-locker-styles';
|
||||||
styleEl.textContent = `
|
styleEl.textContent = `
|
||||||
.note-locker-icon {
|
.note-locker-icon {
|
||||||
display: inline-flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-left: 4px;
|
margin-left: 6px;
|
||||||
width: 12px;
|
width: 14px;
|
||||||
height: 12px;
|
height: 14px;
|
||||||
font-size: 0.85em;
|
|
||||||
color: var(--text-accent);
|
color: var(--text-accent);
|
||||||
vertical-align: middle;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
.nav-file-title {
|
.nav-file-title, .nav-folder-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
.nav-file-title-content {
|
.nav-file-title-content, .nav-folder-title-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
@ -38,43 +37,12 @@ export class FileExplorerUI {
|
||||||
`;
|
`;
|
||||||
document.head.appendChild(styleEl);
|
document.head.appendChild(styleEl);
|
||||||
|
|
||||||
// Initial update
|
|
||||||
this.plugin.app.workspace.onLayoutReady(() => {
|
this.plugin.app.workspace.onLayoutReady(() => {
|
||||||
this.updateFileExplorerIcons();
|
this.updateFileExplorerIcons();
|
||||||
this.setupFolderObserver();
|
this.setupFolderObserver();
|
||||||
|
|
||||||
// Register handlers for folder expansion/collapse
|
|
||||||
this.registerFolderClickHandlers();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private registerFolderClickHandlers(): void {
|
|
||||||
const fileExplorer = document.querySelector('.workspace-split.mod-left-split .nav-files-container');
|
|
||||||
if (!fileExplorer) return;
|
|
||||||
|
|
||||||
fileExplorer.addEventListener('click', (e) => {
|
|
||||||
const target = e.target as HTMLElement;
|
|
||||||
const folderCollapseIndicator = target.closest('.nav-folder-collapse-indicator') ||
|
|
||||||
target.closest('.nav-folder-title');
|
|
||||||
|
|
||||||
if (folderCollapseIndicator) {
|
|
||||||
// A folder was clicked, so schedule an update after DOM changes
|
|
||||||
this.debouncedUpdateIcons(250);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private debouncedUpdateIcons(delay: number = 100): void {
|
|
||||||
if (this.updateDebounceTimeout !== null) {
|
|
||||||
window.clearTimeout(this.updateDebounceTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.updateDebounceTimeout = window.setTimeout(() => {
|
|
||||||
this.updateFileExplorerIcons();
|
|
||||||
this.updateDebounceTimeout = null;
|
|
||||||
}, delay);
|
|
||||||
}
|
|
||||||
|
|
||||||
private setupFolderObserver(): void {
|
private setupFolderObserver(): void {
|
||||||
if (this.folderObserver) {
|
if (this.folderObserver) {
|
||||||
this.folderObserver.disconnect();
|
this.folderObserver.disconnect();
|
||||||
|
|
@ -88,59 +56,150 @@ export class FileExplorerUI {
|
||||||
let shouldUpdate = false;
|
let shouldUpdate = false;
|
||||||
|
|
||||||
for (const mutation of mutations) {
|
for (const mutation of mutations) {
|
||||||
if (mutation.addedNodes.length > 0 || mutation.removedNodes.length > 0) {
|
if (mutation.target instanceof HTMLElement &&
|
||||||
shouldUpdate = true;
|
(mutation.target.classList.contains('note-locker-icon') ||
|
||||||
break;
|
mutation.target.closest('.note-locker-icon'))) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mutation.type === 'attributes' &&
|
if (mutation.type === 'childList') {
|
||||||
mutation.target instanceof HTMLElement &&
|
const target = mutation.target as HTMLElement;
|
||||||
(mutation.target.classList.contains('nav-folder') ||
|
const isTitle = target.classList.contains('nav-file-title') || target.classList.contains('nav-folder-title');
|
||||||
mutation.target.classList.contains('is-collapsed'))) {
|
|
||||||
shouldUpdate = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldUpdate) {
|
let shouldProcess = false;
|
||||||
this.debouncedUpdateIcons(150);
|
|
||||||
|
for (let i = 0; i < mutation.addedNodes.length; i++) {
|
||||||
|
const node = mutation.addedNodes[i];
|
||||||
|
if (!(node instanceof HTMLElement && node.classList.contains('note-locker-icon'))) {
|
||||||
|
shouldProcess = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldProcess) {
|
||||||
|
for (let i = 0; i < mutation.removedNodes.length; i++) {
|
||||||
|
shouldProcess = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldProcess) {
|
||||||
|
if (isTitle) {
|
||||||
|
const container = target.parentElement;
|
||||||
|
if (container) this.processItem(container);
|
||||||
|
} else {
|
||||||
|
this.handleAddedNodes(mutation.addedNodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (mutation.type === 'attributes') {
|
||||||
|
if (mutation.target instanceof HTMLElement) {
|
||||||
|
if (mutation.target.classList.contains('nav-file') || mutation.target.classList.contains('nav-folder')) {
|
||||||
|
this.processItem(mutation.target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.folderObserver.observe(fileExplorer, {
|
this.folderObserver.observe(fileExplorer, {
|
||||||
childList: true,
|
childList: true,
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeFilter: ['class'],
|
attributeFilter: ['class', 'data-path', 'is-collapsed'],
|
||||||
subtree: true
|
subtree: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private handleAddedNodes(nodeList: NodeList): void {
|
||||||
|
nodeList.forEach((node) => {
|
||||||
|
if (node instanceof HTMLElement) {
|
||||||
|
if (node.classList.contains('nav-file') || node.classList.contains('nav-folder')) {
|
||||||
|
this.processItem(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.classList.contains('nav-file-title') || node.classList.contains('nav-folder-title')) {
|
||||||
|
const container = node.parentElement;
|
||||||
|
if (container) this.processItem(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = node.querySelectorAll('.nav-file, .nav-folder');
|
||||||
|
items.forEach(item => this.processItem(item as HTMLElement));
|
||||||
|
|
||||||
|
const titles = node.querySelectorAll('.nav-file-title, .nav-folder-title');
|
||||||
|
titles.forEach(title => {
|
||||||
|
const container = title.parentElement;
|
||||||
|
if (container) this.processItem(container);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private processItem(item: HTMLElement): void {
|
||||||
|
const titleEl = item.querySelector('.nav-file-title, .nav-folder-title');
|
||||||
|
if (!titleEl) return;
|
||||||
|
|
||||||
|
const path = titleEl.getAttribute('data-path');
|
||||||
|
if (!path) return;
|
||||||
|
|
||||||
|
let shouldHaveIcon = false;
|
||||||
|
if (item.classList.contains('nav-file')) {
|
||||||
|
shouldHaveIcon = this.plugin.settings.lockedNotes.has(path);
|
||||||
|
} else if (item.classList.contains('nav-folder')) {
|
||||||
|
shouldHaveIcon = this.plugin.settings.lockedFolders.has(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateIconState(titleEl, shouldHaveIcon);
|
||||||
|
}
|
||||||
|
|
||||||
public updateFileExplorerIcons(): void {
|
public updateFileExplorerIcons(): void {
|
||||||
if (!this.plugin.settings.showFileExplorerIcons) {
|
if (!this.plugin.settings.showFileExplorerIcons) {
|
||||||
this.removeFileExplorerIcons();
|
this.removeFileExplorerIcons();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, remove existing icons to avoid duplicates
|
// Handle files
|
||||||
this.removeFileExplorerIcons();
|
|
||||||
|
|
||||||
// Get all file elements in the file explorer
|
|
||||||
const fileItems = document.querySelectorAll('.nav-file');
|
const fileItems = document.querySelectorAll('.nav-file');
|
||||||
|
|
||||||
fileItems.forEach((fileItem) => {
|
fileItems.forEach((fileItem) => {
|
||||||
const titleEl = fileItem.querySelector('.nav-file-title');
|
const titleEl = fileItem.querySelector('.nav-file-title');
|
||||||
if (!titleEl) return;
|
if (!titleEl) return;
|
||||||
|
|
||||||
const filePath = titleEl.getAttribute('data-path');
|
const filePath = titleEl.getAttribute('data-path');
|
||||||
if (!filePath || !this.plugin.settings.lockedNotes.has(filePath)) return;
|
if (!filePath) return;
|
||||||
|
|
||||||
// Create lock icon element
|
// Only show icon if file is explicitly locked
|
||||||
const iconEl = document.createElement('div');
|
const shouldHaveIcon = this.plugin.settings.lockedNotes.has(filePath);
|
||||||
iconEl.addClass('note-locker-icon');
|
this.updateIconState(titleEl, shouldHaveIcon);
|
||||||
setIcon(iconEl, 'lock');
|
|
||||||
|
|
||||||
titleEl.appendChild(iconEl);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle folders
|
||||||
|
const folderItems = document.querySelectorAll('.nav-folder');
|
||||||
|
folderItems.forEach((folderItem) => {
|
||||||
|
const titleEl = folderItem.querySelector('.nav-folder-title');
|
||||||
|
if (!titleEl) return;
|
||||||
|
|
||||||
|
const folderPath = titleEl.getAttribute('data-path');
|
||||||
|
if (!folderPath) return;
|
||||||
|
|
||||||
|
const shouldHaveIcon = this.plugin.settings.lockedFolders.has(folderPath);
|
||||||
|
this.updateIconState(titleEl, shouldHaveIcon);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private updateIconState(targetEl: Element, shouldHaveIcon: boolean): void {
|
||||||
|
const existingIcon = targetEl.querySelector('.note-locker-icon');
|
||||||
|
|
||||||
|
if (shouldHaveIcon) {
|
||||||
|
if (!existingIcon) {
|
||||||
|
const iconEl = document.createElement('div');
|
||||||
|
iconEl.addClass('note-locker-icon');
|
||||||
|
setIcon(iconEl, 'lock');
|
||||||
|
targetEl.appendChild(iconEl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (existingIcon) {
|
||||||
|
existingIcon.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeFileExplorerIcons(): void {
|
public removeFileExplorerIcons(): void {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue