MCPcopy Create free account
hub / github.com/UNLINEARITY/Obsidian-CodeSpace / constructor

Method constructor

src/main.ts:18–76  ·  view source on GitHub ↗
(app: App, basePath: string, onSubmit: (result: string) => void)

Source from the content-addressed store, hash-verified

16 private folderBtn: ButtonComponent;
17
18 constructor(app: App, basePath: string, onSubmit: (result: string) => void) {
19 super(app);
20 this.currentPath = basePath;
21 this.onSubmit = onSubmit;
22 this.setTitle(t('MODAL_CREATE_TITLE'));
23
24 // Input Group Container
25 const inputGroup = this.contentEl.createDiv({ cls: "create-file-input-group" });
26
27 // Filename Input
28 const nameInput = new TextComponent(inputGroup);
29 nameInput.setPlaceholder("Example: script.py");
30 nameInput.inputEl.addClass("create-file-filename-input");
31
32 // Folder Selection Button
33 this.folderBtn = new ButtonComponent(inputGroup);
34 this.updateButtonText();
35 this.folderBtn.setTooltip(t('SETTINGS_NEW_FILE_LOCATION_BUTTON'));
36 this.folderBtn.onClick(() => {
37 new FolderSuggestModal(this.app, (folder) => {
38 this.currentPath = folder.path;
39 this.updateButtonText();
40 }).open();
41 });
42
43 // Description
44 this.contentEl.createDiv({
45 text: t('MODAL_CREATE_DESC'),
46 cls: "setting-item-description"
47 });
48
49 // 按钮容器
50 const buttonContainer = this.contentEl.createDiv({ cls: "modal-button-container" });
51
52 const submitBtn = new ButtonComponent(buttonContainer);
53 submitBtn.setButtonText(t('MODAL_CREATE_BUTTON_SUBMIT'));
54 submitBtn.setCta();
55 submitBtn.onClick(() => {
56 this.submit(nameInput.getValue());
57 });
58
59 const cancelBtn = new ButtonComponent(buttonContainer);
60 cancelBtn.setButtonText(t('MODAL_CREATE_BUTTON_CANCEL'));
61 cancelBtn.onClick(() => {
62 this.close();
63 });
64
65 // 聚焦到输入框
66 window.setTimeout(() => nameInput.inputEl.focus(), 10);
67
68 // 支持回车确认
69 nameInput.inputEl.addEventListener("keydown", (e: KeyboardEvent) => {
70 if (e.key === "Enter") {
71 e.preventDefault();
72 e.stopPropagation();
73 this.submit(nameInput.getValue());
74 }
75 });

Callers

nothing calls this directly

Calls 6

updateButtonTextMethod · 0.95
submitMethod · 0.95
tFunction · 0.90
getValueMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected