-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodals.ts
More file actions
73 lines (59 loc) · 1.88 KB
/
modals.ts
File metadata and controls
73 lines (59 loc) · 1.88 KB
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
import { App, Modal } from "obsidian";
import { t } from "./i18n";
export class RevertConfirmModal extends Modal {
private files: string[];
private onConfirm: () => void;
private onDiffRequest: (filePath: string) => void;
constructor(app: App, files: string[], onConfirm: () => void, onDiffRequest: (filePath: string) => void) {
super(app);
this.files = files;
this.onConfirm = onConfirm;
this.onDiffRequest = onDiffRequest;
}
onOpen() {
const i18n = t();
const { contentEl } = this;
this.setTitle(i18n.revertConfirmTitle);
contentEl.createEl("p", { text: i18n.revertConfirmDesc });
const listEl = contentEl.createEl("ul", { cls: "revert-file-list" });
this.files.forEach((file) => {
listEl.createEl("li", { text: file + " " })
.createEl("a", { href: "#", text: i18n.revertViewChanges })
.addEventListener("click", () => this.onDiffRequest(file));
});
const buttonContainer = contentEl.createDiv({ cls: "modal-button-container" });
buttonContainer.createEl("button", { text: i18n.revertCancelButton }).addEventListener("click", () => {
this.close();
});
const confirmBtn = buttonContainer.createEl("button", {
text: i18n.revertConfirmButton,
cls: "mod-warning",
});
confirmBtn.addEventListener("click", () => {
this.close();
this.onConfirm();
});
}
onClose() {
this.contentEl.empty();
}
}
export class ViewDiffModal extends Modal {
private title: string;
private diff: string;
constructor(app: App, title: string, diff: string) {
super(app);
this.title = title;
this.diff = diff;
}
onOpen() {
this.setTitle(this.title);
const preview = this.contentEl.createEl("div", { cls: "diff-preview-modal" });
preview.createEl("pre").setText(this.diff);
// MarkdownRenderer
// .render(this.app, "```diff\n" + this.diff + "\n```", preview, "", new MarkdownRenderChild(preview));
}
onClose() {
this.contentEl.empty();
}
}