Skip to content

Commit 86b7368

Browse files
fix obsidian requirements
1 parent 9e555c2 commit 86b7368

File tree

8 files changed

+560
-275
lines changed

8 files changed

+560
-275
lines changed

main.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
1616
//- Commands
1717
this.addCommand({
1818
id: "New-Brother",
19-
name: "newBrother",
19+
name: "new_brother",
2020
callback: () => {
2121
this.createClusterFolder();
2222
this.checkForAdvancedURI_Plugin();
@@ -25,7 +25,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
2525
});
2626
this.addCommand({
2727
id: "New-Son",
28-
name: "newSon",
28+
name: "new_son",
2929
callback: () => {
3030
this.createClusterFolder();
3131
this.checkForAdvancedURI_Plugin();
@@ -34,7 +34,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
3434
});
3535
this.addCommand({
3636
id: "New-Cluster",
37-
name: "newCluster",
37+
name: "new_cluster",
3838
callback: () => {
3939
this.createClusterFolder();
4040
this.checkForAdvancedURI_Plugin();
@@ -43,7 +43,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
4343
});
4444
this.addCommand({
4545
id: "Delete-Active-Note",
46-
name: "DeleteActiveNote",
46+
name: "delete_active_note",
4747
callback: () => {
4848
this.createClusterFolder();
4949
this.checkForAdvancedURI_Plugin();

src/createFamily/deleteActiveNoteModal.ts

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { App, Notice, Modal, TFolder } from "obsidian";
1+
import { App, Notice, Modal, TFolder, TFile } from "obsidian";
22
import { NewFileLocation } from "../util/enums";
33
import svgElements from "./svg";
44

@@ -9,7 +9,7 @@ export default class deleteActiveNoteModal extends Modal {
99
inputEl: HTMLInputElement;
1010
inputListener: EventListener;
1111
createType: string;
12-
deleteMsg:string
12+
1313
constructor(app: App, mode: NewFileLocation, createType: string) {
1414
super(app);
1515
this.createType = createType;
@@ -23,30 +23,30 @@ export default class deleteActiveNoteModal extends Modal {
2323
this.inputEl.addClasses(["prompt-input","inputDelete"])
2424

2525
//-Delete message
26-
const theRelatedSonsFolder = getActiveFile.parent.children.find((item : any ) => {
26+
const theRelatedSonsFolder = getActiveFile?.parent?.children.find((item : any ) => {
27+
//normale note
2728
if(item instanceof TFolder && item.name == getActiveFile.basename.toUpperCase() ){
2829
return item
2930
}
31+
// cluster
32+
if(item instanceof TFolder && getActiveFile?.basename.endsWith("cluster") && item.name == getActiveFile.basename ){
33+
return item
34+
}
3035
})
31-
36+
const text = document.createElement('div');
37+
text.addClass("delMsg")
3238
if(theRelatedSonsFolder){
33-
//@ts-ignore
34-
this.deleteMsg =`<span>Press enter ↵ to delete current <span class="delNoteNameMsg">${getActiveFile.basename}</span> note</br>with its related [<span class="delNoteNameMsg">${theRelatedSonsFolder.children.length}</span>] sons in [${getActiveFile.basename.toUpperCase()}] folder</br>or ESC to dismiss.</span>`
39+
text.appendChild(this.createDeleteMsg1(getActiveFile , theRelatedSonsFolder))
3540
}else{
36-
this.deleteMsg = `<span>Press enter ↵ to delete current <span class="delNoteNameMsg">${getActiveFile.basename}</span> note or ESC to dismiss.</span>`
41+
text.appendChild(this.createDeleteMsg2(getActiveFile))
3742
}
3843
//-Make modal
3944
this.modalEl.className = "prompt";
40-
this.modalEl.innerHTML = "";
45+
4146
//svg
4247
if (this.createType == "deleteNote") {
4348
this.modalEl.appendChild(svgElements().delete());
4449
}
45-
//txt msg
46-
const text = document.createElement('div');
47-
text.innerHTML = this.deleteMsg
48-
text.addClass("delMsg")
49-
5050

5151
this.modalEl.appendChild(text);
5252
this.modalEl.appendChild(this.inputEl);
@@ -65,38 +65,99 @@ export default class deleteActiveNoteModal extends Modal {
6565

6666

6767
//parent folder info
68-
const theContainingFolder = getActiveFile.parent.children.length
69-
const theContainingFolderPath = getActiveFile.parent.path
68+
const theContainingFolder = getActiveFile!.parent!.children.length
69+
const theContainingFolderPath = getActiveFile!.parent!.path
7070
//Related Sons Folder
71-
const theRelatedSonsFolder = getActiveFile.parent.children.find((item : any ) => {
72-
if(item instanceof TFolder && item.name == getActiveFile.basename.toUpperCase() ){
71+
const theRelatedSonsFolder = getActiveFile!.parent!.children.find((item : any ) => {
72+
// normal note
73+
if(item instanceof TFolder && item.name == getActiveFile!.basename.toUpperCase() ){
74+
return item
75+
}
76+
// cluster
77+
if(item instanceof TFolder && getActiveFile?.basename.endsWith("cluster") && item.name == getActiveFile.basename ){
7378
return item
7479
}
7580
})
7681

7782
if(theRelatedSonsFolder){
7883
//delete current active file + delete its Sons
79-
await this.app.vault.adapter.remove(getActiveFile.path)
84+
await this.app.vault.adapter.remove(getActiveFile!.path)
8085
await this.app.vault.adapter.rmdir(theRelatedSonsFolder.path , true)
86+
console.log(theRelatedSonsFolder)
8187
if(theContainingFolder == 2){
8288
await this.app.vault.adapter.rmdir(theContainingFolderPath , true)
8389
}
8490
}else{
8591
//delete current active file
86-
await this.app.vault.adapter.remove(getActiveFile.path)
92+
await this.app.vault.adapter.remove(getActiveFile!.path)
8793

8894
}
8995

9096
//delete parent folder of active file if it is empty
9197
if(theContainingFolder == 1 ){
9298
await this.app.vault.adapter.rmdir(theContainingFolderPath , true)
93-
console.log("dddddddddd")
94-
console.log(theContainingFolder)
9599
}
96100
this.close();
97101
}
98102
}
103+
createDeleteMsg1(activeFile : any , theRelatedSonsFolder : any){
104+
// Create the container element
105+
const deleteMsgContainer = document.createElement('div');
106+
107+
// Create and append child elements
108+
const text1 = document.createElement('span');
109+
text1.textContent = 'Press enter ↵ to delete current ';
110+
deleteMsgContainer.appendChild(text1);
111+
112+
const delNoteNameMsg1 = document.createElement('span');
113+
delNoteNameMsg1.classList.add('delNoteNameMsg');
114+
delNoteNameMsg1.textContent = activeFile.basename;
115+
deleteMsgContainer.appendChild(delNoteNameMsg1);
116+
117+
const text2 = document.createElement('span');
118+
text2.textContent = activeFile.basename.endsWith("-cluster") ? ' cluster' : ' note';
119+
deleteMsgContainer.appendChild(text2);
120+
121+
const lineBreak = document.createElement('br');
122+
deleteMsgContainer.appendChild(lineBreak);
123+
124+
const text3 = document.createElement('span');
125+
text3.textContent = 'with its related[';
126+
deleteMsgContainer.appendChild(text3);
127+
128+
const delNoteNameMsg2 = document.createElement('span');
129+
delNoteNameMsg2.classList.add('delNoteNameMsg');
130+
delNoteNameMsg2.textContent = `${theRelatedSonsFolder.children.length}`;
131+
deleteMsgContainer.appendChild(delNoteNameMsg2);
132+
133+
const text4 = document.createElement('span');
134+
text4.textContent = '] sons in [' + activeFile.basename.toUpperCase() + '] folder';
135+
deleteMsgContainer.appendChild(text4);
136+
137+
return deleteMsgContainer
138+
139+
}
140+
createDeleteMsg2(activeFile : any ){
141+
// Create the container element
142+
const deleteMsgContainer = document.createElement('div');
143+
144+
// Create and append child elements
145+
const text1 = document.createElement('span');
146+
text1.textContent = 'Press enter ↵ to delete current ';
147+
deleteMsgContainer.appendChild(text1);
148+
149+
const delNoteNameMsg1 = document.createElement('span');
150+
delNoteNameMsg1.classList.add('delNoteNameMsg');
151+
delNoteNameMsg1.textContent = activeFile.basename;
152+
deleteMsgContainer.appendChild(delNoteNameMsg1);
99153

154+
const text2 = document.createElement('span');
155+
text2.textContent = activeFile.basename.endsWith("-cluster") ? ' cluster' : ' note';
156+
deleteMsgContainer.appendChild(text2);
157+
158+
return deleteMsgContainer
159+
160+
}
100161
onOpen() {
101162
this.inputEl.focus();
102163
this.inputEl.addEventListener("keydown", this.inputListener);

src/createFamily/familyModal.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default class familyModal extends Modal {
1010
folder: TFolder;
1111
newDirectoryPath: string;
1212
inputEl: HTMLInputElement;
13-
shouldMakeDir: string;
13+
shouldMakeDir: string | undefined;
1414
inputListener: EventListener;
1515
createType: string;
1616
constructor(app: App, mode: NewFileLocation, createType: string) {
@@ -26,9 +26,10 @@ export default class familyModal extends Modal {
2626

2727
//#region Make modal
2828
this.modalEl.className = 'prompt';
29-
this.modalEl.innerHTML = '';
29+
3030
//svg and placeholders
3131
let getActiveFile = app.workspace.getActiveFile()
32+
3233
if(getActiveFile === null){
3334

3435
this.inputEl.addClasses(["prompt-input","inputDelete"])
@@ -40,10 +41,10 @@ export default class familyModal extends Modal {
4041

4142
this.modalEl.appendChild(text);
4243
}else if (this.createType == "newSon") {
43-
this.inputEl.placeholder = `Type the son name of [${getActiveFile}] note`;
44+
this.inputEl.placeholder = `Type the son name of [${getActiveFile.basename}] note`;
4445
this.modalEl.appendChild(svgElements().son());
4546
} else if (this.createType == "newBrother") {
46-
this.inputEl.placeholder = `Type the brother name of [${getActiveFile}] note`;
47+
this.inputEl.placeholder = `Type the brother name of [${getActiveFile.basename}] note`;
4748
this.modalEl.appendChild(svgElements().brother());
4849
} else if (this.createType == "newCluster") {
4950
this.inputEl.placeholder = `Type the new Cluster name`;
@@ -71,23 +72,24 @@ export default class familyModal extends Modal {
7172
// prevent enter after note creation
7273
evt.preventDefault();
7374

75+
console.log(evt)
7476
// get current active file
7577
const getActiveFile = app.workspace.getActiveFile();
7678

77-
const currentActiveFileName = getActiveFile.basename;
79+
const currentActiveFileName = getActiveFile?.basename;
7880

7981

8082
//-make clusterSon to the current active file
8183
if (this.createType == "newSon") {
82-
if(getActiveFile.path.startsWith("[CLUSTERS]")){
84+
if(getActiveFile?.path.startsWith("[CLUSTERS]")){
8385
if(getActiveFile.basename.endsWith("-cluster") ){
8486
if( (getActiveFile.path.match(/\//g) || []).length == 1 ){
8587
const result = await templates(getActiveFile,"clusterSon");
8688
if (result.state) {
8789

88-
const sonsFolderPath = `${getActiveFile.parent.path}/${currentActiveFileName}`;
90+
const sonsFolderPath = `${getActiveFile?.parent?.path}/${currentActiveFileName}`;
8991
await this.createDirectory("", sonsFolderPath);
90-
const newCreatedSonsFolder = getActiveFile.parent.children.find(
92+
const newCreatedSonsFolder = getActiveFile.parent?.children.find(
9193
(item: any) => item instanceof TFolder && item.name == `${currentActiveFileName}`
9294
);
9395

@@ -108,10 +110,10 @@ export default class familyModal extends Modal {
108110
const result = await templates(getActiveFile,"normalSon");
109111

110112
if (result.state) {
111-
const sonsFolderPath = `${getActiveFile.parent.path}/${currentActiveFileName.toUpperCase()}`;
113+
const sonsFolderPath = `${getActiveFile!.parent!.path}/${currentActiveFileName?.toUpperCase()}`;
112114
await this.createDirectory("", sonsFolderPath);
113-
const newCreatedSonsFolder = getActiveFile.parent.children.find(
114-
(item: any) => item instanceof TFolder && item.name == currentActiveFileName.toUpperCase()
115+
const newCreatedSonsFolder = getActiveFile.parent!.children.find(
116+
(item: any) => item instanceof TFolder && item.name == currentActiveFileName!.toUpperCase()
115117
);
116118

117119
// @ts-ignore
@@ -132,15 +134,15 @@ export default class familyModal extends Modal {
132134
}
133135
//-make Brother to the current active file
134136
else if (this.createType == "newBrother") {
135-
if(getActiveFile.path.startsWith("[CLUSTERS]")){
137+
if(getActiveFile!.path.startsWith("[CLUSTERS]")){
136138
// the next if statement to prevent make brother to a cluster
137-
if (currentActiveFileName.endsWith("-cluster")) {
139+
if (currentActiveFileName!.endsWith("-cluster")) {
138140
new Notice(`You cant make Brother to a cluster.\nCreate new cluster instead`);
139141
} else {
140142
const result = await templates(getActiveFile,"brother");
141143

142144
if (result.state == true) {
143-
this.setFolder( getActiveFile.parent, "");
145+
this.setFolder( getActiveFile!.parent!, "");
144146
this.createNewNote(this.inputEl.value, result.brotherTemplate);
145147
}
146148
}
@@ -260,6 +262,7 @@ export default class familyModal extends Modal {
260262
// Create the file and open it in the active leaf
261263
let leaf = this.app.workspace.getLeaf(false);
262264
if (this.mode === NewFileLocation.NewPane) {
265+
//@ts-ignore
263266
leaf = this.app.workspace.splitLeafOrActive();
264267
} else if (this.mode === NewFileLocation.NewTab) {
265268
leaf = this.app.workspace.getLeaf(true);

0 commit comments

Comments
 (0)