-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ccd105
commit 0897e08
Showing
2 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Modal, Setting } from "obsidian"; | ||
import ObsidianAdmonition from "src/main"; | ||
|
||
export default class Export extends Modal { | ||
constructor(public plugin: ObsidianAdmonition) { | ||
super(app); | ||
} | ||
admonitionDefinitions = Object.values(this.plugin.data.userAdmonitions); | ||
|
||
admonitionNames = Object.keys(this.plugin.data.userAdmonitions); | ||
|
||
selectedAdmonitions = [...this.admonitionNames]; | ||
|
||
export = false; | ||
|
||
onOpen() { | ||
this.titleEl.setText("Export Admonitions"); | ||
this.containerEl.addClasses([ | ||
"admonition-settings", | ||
"admonition-modal", | ||
"admonition-export-modal" | ||
]); | ||
new Setting(this.contentEl).addButton((b) => | ||
b.setButtonText("Export Selected").onClick(() => { | ||
this.export = true; | ||
this.close(); | ||
}) | ||
); | ||
let toggleEl: HTMLDivElement; | ||
new Setting(this.contentEl) | ||
.addButton((b) => | ||
b | ||
.setButtonText("Select All") | ||
.setCta() | ||
.onClick(() => { | ||
this.selectedAdmonitions = [...this.admonitionNames]; | ||
this.generateToggles(toggleEl); | ||
}) | ||
) | ||
.addButton((b) => | ||
b.setButtonText("Deselect All").onClick(() => { | ||
this.selectedAdmonitions = []; | ||
this.generateToggles(toggleEl); | ||
}) | ||
); | ||
toggleEl = this.contentEl.createDiv("additional"); | ||
this.generateToggles(toggleEl); | ||
} | ||
|
||
generateToggles(toggleEl: HTMLDivElement) { | ||
toggleEl.empty(); | ||
for (const name of this.admonitionNames) { | ||
new Setting(toggleEl).setName(name).addToggle((t) => { | ||
t.setValue(this.selectedAdmonitions.includes(name)).onChange( | ||
(v) => { | ||
if (v) { | ||
this.selectedAdmonitions.push(name); | ||
} else { | ||
this.selectedAdmonitions.remove(name); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters