@@ -4,7 +4,6 @@ import {
|
||||
MarkdownFileInfo,
|
||||
MarkdownView,
|
||||
Notice,
|
||||
PluginSettingTab,
|
||||
Setting,
|
||||
normalizePath,
|
||||
} from 'obsidian';
|
||||
@@ -33,25 +32,45 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
||||
|
||||
onload(plugin: ZeroQoLModulesPlugin, moduleSettings: Record<string, unknown>): void {
|
||||
this.app = plugin.app;
|
||||
const settings = moduleSettings as unknown as AttachmentCleanPasteSettings;
|
||||
|
||||
plugin.addSettingTab(
|
||||
new AttachmentCleanPasteSettingTab(plugin.app, plugin, MODULE_ID),
|
||||
);
|
||||
const rawSettings = moduleSettings as AttachmentCleanPasteSettings;
|
||||
|
||||
const pasteRef = plugin.app.workspace.on(
|
||||
'editor-paste',
|
||||
this.createPasteHandler(settings),
|
||||
this.createPasteHandler(rawSettings),
|
||||
);
|
||||
this.registerCleanup(() => plugin.app.workspace.offref(pasteRef));
|
||||
|
||||
const dropRef = plugin.app.workspace.on(
|
||||
'editor-drop',
|
||||
this.createDropHandler(settings),
|
||||
this.createDropHandler(rawSettings),
|
||||
);
|
||||
this.registerCleanup(() => plugin.app.workspace.offref(dropRef));
|
||||
}
|
||||
|
||||
renderInlineSettings(
|
||||
containerEl: HTMLElement,
|
||||
settings: Record<string, unknown>,
|
||||
saveSettings: () => Promise<void>,
|
||||
): void {
|
||||
const loc = locale.modules['attachment-clean-paste'];
|
||||
const extSettings = settings as unknown as AttachmentCleanPasteSettings;
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(loc.extensionsLabel)
|
||||
.setDesc(loc.extensionsDesc)
|
||||
.addTextArea((textarea) => {
|
||||
textarea
|
||||
.setPlaceholder(loc.extensionsPlaceholder)
|
||||
.setValue(extSettings?.extensions ?? '')
|
||||
.onChange(async (value) => {
|
||||
settings.extensions = value;
|
||||
await saveSettings();
|
||||
});
|
||||
textarea.inputEl.rows = 4;
|
||||
textarea.inputEl.style.width = '100%';
|
||||
});
|
||||
}
|
||||
|
||||
private createPasteHandler(settings: AttachmentCleanPasteSettings) {
|
||||
return async (
|
||||
evt: ClipboardEvent,
|
||||
@@ -155,50 +174,3 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AttachmentCleanPasteSettingTab extends PluginSettingTab {
|
||||
private plugin: ZeroQoLModulesPlugin;
|
||||
private moduleId: string;
|
||||
|
||||
constructor(app: App, plugin: ZeroQoLModulesPlugin, moduleId: string) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
this.moduleId = moduleId;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const { containerEl } = this;
|
||||
containerEl.empty();
|
||||
|
||||
const loc = locale.modules['attachment-clean-paste'];
|
||||
|
||||
containerEl.createEl('h2', { text: loc.name });
|
||||
containerEl.createEl('p', {
|
||||
text: loc.descriptionShort,
|
||||
attr: { style: 'color: var(--text-muted); margin-bottom: 20px;' },
|
||||
});
|
||||
|
||||
const rawSettings = this.plugin.settings.modules[this.moduleId]?.settings as
|
||||
| AttachmentCleanPasteSettings
|
||||
| undefined;
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(loc.extensionsLabel)
|
||||
.setDesc(loc.extensionsDesc)
|
||||
.addTextArea((textarea) => {
|
||||
textarea
|
||||
.setPlaceholder(loc.extensionsPlaceholder)
|
||||
.setValue(rawSettings?.extensions ?? '')
|
||||
.onChange(async (value) => {
|
||||
if (this.plugin.settings.modules[this.moduleId]) {
|
||||
this.plugin.settings.modules[this.moduleId].settings = {
|
||||
extensions: value,
|
||||
};
|
||||
}
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
textarea.inputEl.rows = 4;
|
||||
textarea.inputEl.style.width = '100%';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ export abstract class BaseModule implements QoLModule {
|
||||
this.cleanupFns = [];
|
||||
}
|
||||
|
||||
renderInlineSettings(
|
||||
_containerEl: HTMLElement,
|
||||
_settings: Record<string, unknown>,
|
||||
_saveSettings: () => Promise<void>,
|
||||
): void {}
|
||||
|
||||
protected registerCleanup(fn: () => void): void {
|
||||
this.cleanupFns.push(fn);
|
||||
}
|
||||
|
||||
+10
-2
@@ -45,14 +45,14 @@ export class ZeroQSettingTab extends PluginSettingTab {
|
||||
});
|
||||
|
||||
for (const module of MODULES) {
|
||||
const moduleSettings = this.plugin.settings.modules[module.id];
|
||||
const moduleCfg = this.plugin.settings.modules[module.id];
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName(module.name)
|
||||
.setDesc(module.description)
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(moduleSettings?.enabled ?? true)
|
||||
.setValue(moduleCfg?.enabled ?? true)
|
||||
.onChange(async (value) => {
|
||||
if (!this.plugin.settings.modules[module.id]) {
|
||||
this.plugin.settings.modules[module.id] = {
|
||||
@@ -70,6 +70,14 @@ export class ZeroQSettingTab extends PluginSettingTab {
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
if (moduleCfg) {
|
||||
module.renderInlineSettings(
|
||||
containerEl,
|
||||
moduleCfg.settings,
|
||||
() => this.plugin.saveSettings(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,4 +16,9 @@ export interface QoLModule {
|
||||
defaultSettings: Record<string, unknown>;
|
||||
onload(plugin: Plugin, moduleSettings: Record<string, unknown>): void;
|
||||
onunload(plugin: Plugin): void;
|
||||
renderInlineSettings(
|
||||
containerEl: HTMLElement,
|
||||
settings: Record<string, unknown>,
|
||||
saveSettings: () => Promise<void>,
|
||||
): void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user