Skip to content

Commit 6bfe341

Browse files
refactorrrrrrr
1 parent ee5acfd commit 6bfe341

File tree

5 files changed

+92
-82
lines changed

5 files changed

+92
-82
lines changed

main.ts

Lines changed: 14 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,9 @@
11
import { Plugin, TFile} from "obsidian";
2-
import { buttonsLine, cardStyleFunction } from "./src/createFamily/buttons";
3-
import {
4-
coloringTreePanel,
5-
addUnsortedFilesCounter,
6-
unSortedObserver,
7-
foldPropertiesElement,
8-
} from "./src/createFamily/coloringTreePanel";
9-
import { fileMenu } from "src/mainParts/fileMenu";
10-
import { settingTab } from "./src/createFamily/settings";
11-
import SimpleFocusClass from "src/focus/simpleFocus";
12-
import { addCommands } from "src/mainParts/addCommands";
13-
import { addRibbonIcon } from "src/mainParts/addRibbonIcon";
2+
import P from "src/util/P";
3+
import { settingTab ,DEFAULT_SETTINGS ,clusterPluginSettings } from "./src/settings/settings";
144

15-
const SimpleFocus = new SimpleFocusClass();
16-
17-
18-
export interface clusterPluginSettings {
19-
foldProperties: boolean;
20-
21-
firstPageClusters: boolean;
22-
cardStyle: boolean;
23-
restBgClusters: boolean;
24-
newBG_clusters: string;
25-
newBG_orphans: string;
26-
restBgOrphans: boolean;
27-
buttonsLineContainerBG_clusters: string;
28-
buttonsLineContainerBG_orphans: string;
29-
}
30-
31-
const DEFAULT_SETTINGS: Partial<clusterPluginSettings> = {
32-
foldProperties: true,
33-
34-
firstPageClusters: true,
35-
cardStyle: false,
36-
restBgClusters: true,
37-
restBgOrphans: true,
38-
buttonsLineContainerBG_clusters:
39-
"var(--background-button-container-clusters)",
40-
buttonsLineContainerBG_orphans: "var(--background-button-container-orphans)",
41-
};
425

436
export default class clusterPlugin extends Plugin {
44-
actions = new Map(); // ! whats this
457
settings: clusterPluginSettings;
468

479
async onload() {
@@ -51,44 +13,22 @@ export default class clusterPlugin extends Plugin {
5113

5214
this.addSettingTab(new settingTab(this.app, this));
5315

54-
//- UN-SORTED Folder Styling
16+
// UN-SORTED Folder Styling
5517
setTimeout(async () => {
56-
await addUnsortedFilesCounter(this.app);
57-
await unSortedObserver(this.app);
18+
await P.addUnsortedFilesCounter(this.app);
19+
await P.unSortedObserver(this.app);
5820
}, 1000);
59-
//- Card style
60-
await cardStyleFunction( this.settings);
21+
22+
await P.cardStyleFunction( this.settings);//card style for lorens theme
6123

6224
const file = this.app.workspace.getActiveFile() as TFile;
6325
if (file) {
64-
await buttonsLine(this.app, file, this.settings);
26+
await P.buttonsLine(this.app, file, this.settings);
6527
}
66-
67-
this.registerEvent(
68-
this.app.workspace.on("file-open", async (file) => {
69-
if (file) {
70-
//- Add Buttons
71-
await buttonsLine(this.app, file, this.settings);
72-
73-
//- Coloring Tree Panel
74-
await coloringTreePanel(this.app, file);
75-
//- Fold Properties Element
76-
if (this.settings.foldProperties) {
77-
await foldPropertiesElement(this.app, file);
78-
}
79-
await addUnsortedFilesCounter(this.app);
80-
await unSortedObserver(this.app);
81-
}
82-
}),
83-
);
84-
85-
86-
//- add Ribbon Icon
87-
addRibbonIcon( this);
88-
//- File Menu
89-
fileMenu(this,SimpleFocus);
90-
//- Commands
91-
addCommands(this);
28+
P.addEvents(this)
29+
P.addRibbonIcon( this);
30+
P.fileMenu(this,P.SimpleFocus);
31+
P.addCommands(this);
9232
}
9333

9434
async loadSettings() {
@@ -103,8 +43,8 @@ export default class clusterPlugin extends Plugin {
10343
//FIX if there more than one file in workspace you need to remove the buttons line from them all
10444
// Remove Buttons line
10545
const file = this.app.workspace.getActiveFile() as TFile;
106-
await buttonsLine(this.app, file, this.settings, true);
107-
unSortedObserver(this.app, false);
46+
await P.buttonsLine(this.app, file, this.settings, true);
47+
P.unSortedObserver(this.app, false);
10848
console.log("unloading Cluster plugin");
10949
}
11050
}

src/createFamily/commit_info.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
## Did
22

3-
- [*] this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => { what is this code doing? This seems to just be finding any markdown leaf. Why? Do you mean to access activeLeaf? You probably want to use getActiveViewOfType(MarkdownView) instead.
4-
53
## ToDo
64

75
- [ ] FIX you need to add buttons line when onload if there is an active file
86
- [ ] make the extra buttons [ puzzle ] functionality implementation
97
- [ ] when you rename parent note you need rename the son's containing folder with same name
10-
- [ ] make Scope feature like the one in vs code

src/mainParts/events.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Plugin, TFile } from "obsidian";
2+
import P from "src/util/P";
3+
4+
export function addEvents(plugin: Plugin) {
5+
// watch if file opened
6+
plugin.registerEvent(
7+
this.app.workspace.on("file-open", async (file: TFile) => {
8+
if (file) {
9+
await P.buttonsLine(this.app, file, this.settings); // Add Cluster Buttons
10+
await P.coloringTreePanel(this.app, file);
11+
this.settings.foldProperties ? await P.foldPropertiesElement(this.app, file) : null; // Fold Properties
12+
await P.addUnsortedFilesCounter(this.app);
13+
await P.unSortedObserver(this.app);
14+
}
15+
}),
16+
);
17+
}
Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,35 @@ import {
55
Setting,
66
TextComponent,
77
ToggleComponent,
8-
WorkspaceContainer,
98
Platform,
109
} from "obsidian";
1110

11+
12+
export interface clusterPluginSettings {
13+
foldProperties: boolean;
14+
15+
firstPageClusters: boolean;
16+
cardStyle: boolean;
17+
restBgClusters: boolean;
18+
newBG_clusters: string;
19+
newBG_orphans: string;
20+
restBgOrphans: boolean;
21+
buttonsLineContainerBG_clusters: string;
22+
buttonsLineContainerBG_orphans: string;
23+
}
24+
25+
export const DEFAULT_SETTINGS: Partial<clusterPluginSettings> = {
26+
foldProperties: true,
27+
28+
firstPageClusters: true,
29+
cardStyle: false,
30+
restBgClusters: true,
31+
restBgOrphans: true,
32+
buttonsLineContainerBG_clusters:
33+
"var(--background-button-container-clusters)",
34+
buttonsLineContainerBG_orphans: "var(--background-button-container-orphans)",
35+
};
36+
1237
export class settingTab extends PluginSettingTab {
1338
plugin: clusterPlugin;
1439

@@ -18,7 +43,7 @@ export class settingTab extends PluginSettingTab {
1843
}
1944

2045
display(): void {
21-
let { containerEl } = this;
46+
const { containerEl } = this;
2247

2348
containerEl.empty();
2449
containerEl.classList.add("clusterSettingPage");
@@ -171,7 +196,7 @@ export class settingTab extends PluginSettingTab {
171196
this.plugin.settings.restBgClusters = true;
172197
this.plugin.settings.buttonsLineContainerBG_clusters =
173198
"var(--background-button-container-clusters)";
174-
inputText!.setValue("var(--background-button-container-clusters)");
199+
inputText?.setValue("var(--background-button-container-clusters)");
175200
inputText!.inputEl.style.backgroundColor =
176201
"var(--background-button-container-clusters)";
177202
input.controlEl.classList.add("inputDisable");
@@ -240,7 +265,7 @@ export class settingTab extends PluginSettingTab {
240265
this.plugin.settings.restBgOrphans = true;
241266
this.plugin.settings.buttonsLineContainerBG_orphans =
242267
"var(--background-button-container-orphans)";
243-
inputText!.setValue("var(--background-button-container-orphans)");
268+
inputText?.setValue("var(--background-button-container-orphans)");
244269
inputText!.inputEl.style.backgroundColor =
245270
"var(--background-button-container-orphans)";
246271
input.controlEl.classList.add("inputDisable");
@@ -252,7 +277,7 @@ export class settingTab extends PluginSettingTab {
252277
this.plugin.settings.restBgOrphans = false;
253278
this.plugin.settings.buttonsLineContainerBG_orphans =
254279
this.plugin.settings.newBG_orphans;
255-
inputText!.setValue(this.plugin.settings.newBG_orphans);
280+
inputText?.setValue(this.plugin.settings.newBG_orphans);
256281
inputText!.inputEl.style.backgroundColor =
257282
this.plugin.settings.newBG_orphans;
258283
}

src/util/P.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { fileMenu } from "src/mainParts/fileMenu";
2+
import { addCommands } from "src/mainParts/addCommands";
3+
import { addEvents } from "src/mainParts/events";
4+
import { addRibbonIcon } from "src/mainParts/addRibbonIcon";
5+
6+
import SimpleFocusClass from "src/focus/simpleFocus";
7+
const SimpleFocus = new SimpleFocusClass();
8+
9+
import { buttonsLine, cardStyleFunction } from "../createFamily/buttons";
10+
import {
11+
coloringTreePanel,
12+
addUnsortedFilesCounter,
13+
unSortedObserver,
14+
foldPropertiesElement,
15+
} from "../createFamily/coloringTreePanel";
16+
const P = {
17+
fileMenu,
18+
addEvents,
19+
addCommands,
20+
addRibbonIcon,
21+
SimpleFocus,
22+
buttonsLine,
23+
cardStyleFunction,
24+
coloringTreePanel,
25+
addUnsortedFilesCounter,
26+
unSortedObserver,
27+
foldPropertiesElement,
28+
29+
}
30+
31+
export default P

0 commit comments

Comments
 (0)