forked from chrisgrieser/obsidian-divide-and-conquer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.ts
142 lines (130 loc) · 3.83 KB
/
settings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import {
App,
PluginManifest,
PluginSettingTab,
Setting,
TextAreaComponent,
} from "obsidian";
import divideAndConquer from "main";
export interface DACSettings {
filterRegexes: string[];
filterUsingDisplayName: boolean;
filterUsingAuthor: boolean;
filterUsingDescription: boolean;
reloadAfterPluginChanges: boolean;
disabledState: string;
steps: number;
}
export const DEFAULT_SETTINGS: DACSettings = {
filterRegexes: ["hot-reload", "obsidian-divide-and-conquer"],
filterUsingDisplayName: true,
filterUsingAuthor: false,
filterUsingDescription: false,
reloadAfterPluginChanges: false,
disabledState: undefined,
};
export class DACSettingsTab extends PluginSettingTab {
plugin: divideAndConquer;
constructor(app: App, plugin: divideAndConquer) {
super(app, plugin);
this.plugin = plugin;
}
public display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Divide and Conquer" });
new Setting(containerEl)
.setName("Reload Obsidian after plugin changes")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.reloadAfterPluginChanges)
.onChange(async (value) => {
this.plugin.settings.reloadAfterPluginChanges = value;
await this.plugin.saveData(false);
})
);
containerEl.createEl("p", {
text: "Changing any of the following settings will restore plugins to the original state.",
});
new Setting(containerEl)
.setName("Use Filters on Plugin Display Names")
.setDesc("If this is off, DAC will only match plugins by their ID")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.filterUsingDisplayName)
.onChange(async (value) => {
this.plugin.settings.filterUsingDisplayName = value;
await this.plugin.saveData();
})
);
new Setting(containerEl)
.setName("Use Filters on Plugin Authors")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.filterUsingAuthor)
.onChange(async (value) => {
this.plugin.settings.filterUsingAuthor = value;
await this.plugin.saveData();
})
);
new Setting(containerEl)
.setName("Use Filters on Plugin Descriptions")
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.filterUsingDescription)
.onChange(async (value) => {
this.plugin.settings.filterUsingDescription = value;
await this.plugin.saveData();
})
);
let inputArea: TextAreaComponent;
let exclude = new Setting(containerEl)
.setName("Plugin Exclusions")
.setDesc(
"Exclude plugins using regex (case insensitive).\nEach new line is a new regex. Plugin ids are used for matching by default. Included plugins are on the left, excluded on the right. "
)
.addTextArea((textArea) => {
inputArea = textArea;
textArea.inputEl.setAttr("rows", 10);
textArea.inputEl.style.width = "45%";
textArea
.setPlaceholder(
[
...(this.plugin.getIncludedPlugins(
false
) as Set<PluginManifest>),
]
.map((p) => p.name)
.join("\n")
)
.setDisabled(true);
});
exclude.addTextArea((textArea) => {
textArea.inputEl.setAttr("rows", 10);
textArea.inputEl.style.width = "55%";
textArea
.setPlaceholder("^daily/\n\\.png$\netc...")
.setValue(this.plugin.settings.filterRegexes.join("\n"));
textArea.inputEl.onblur = (e: FocusEvent) => {
const patterns = (e.target as HTMLInputElement).value;
this.plugin.settings.filterRegexes = patterns
.split("\n")
.filter((p) => p.length);
this.plugin.saveData();
inputArea
.setPlaceholder(
[
...(this.plugin.getIncludedPlugins(
false
) as Set<PluginManifest>),
]
.map((p) => p.name)
.join("\n")
)
.setDisabled(true);
};
});
exclude.controlEl.style.width = "100%";
exclude.infoEl.style.width = "45%";
}
}