Skip to content

Commit

Permalink
lots of changes to settings, rendering, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed May 1, 2022
1 parent 645f9dc commit 5742043
Show file tree
Hide file tree
Showing 15 changed files with 684 additions and 230 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@popperjs/core": "^2.11.2"
},
"devDependencies": {
"obsidian-excalidraw-plugin": "1.6.26-6",
"obsidian-excalidraw-plugin": "1.6.26-10",
"@babel/core": "^7.16.12",
"@babel/preset-env": "^7.16.11",
"@babel/preset-react": "^7.16.7",
Expand Down
32 changes: 21 additions & 11 deletions src/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ExcaliBrain from "./main";
import { ExcaliBrainSettings } from "./Settings";
import { SearchBox } from "./Suggesters/SearchBox";
import { Neighbour, RelationType, Role } from "./Types";
import { log } from "./utils/utils";

export class Scene {
settings: ExcaliBrainSettings;
Expand All @@ -31,6 +32,7 @@ export class Scene {
private searchBox: SearchBox;

constructor(plugin: ExcaliBrain, newLeaf: boolean, leaf?: WorkspaceLeaf) {
log("construct scene");
this.settings = plugin.settings;
this.ea = plugin.EA;
this.plugin = plugin;
Expand All @@ -40,6 +42,7 @@ export class Scene {
}

public async initialize() {
log("initialize");
await this.initilizeScene();
this.searchBox = new SearchBox((this.leaf.view as TextFileView).contentEl,this.plugin);
}
Expand All @@ -50,7 +53,7 @@ export class Scene {
*/
public isActive() {
//@ts-ignore
return !this.terminated && app.workspace.getLeafById(this._instance.leaf?.id)
return !this.terminated && app.workspace.getLeafById(this.leaf?.id)
}

/**
Expand Down Expand Up @@ -113,16 +116,16 @@ export class Scene {
await this.render();
}

public async initilizeScene() {
this.disregardLeafChange = false;
public async openExcalidrawLeaf() {
log("openExcalidrawLeaf")
const ea = this.ea;
const style = this.settings.baseNodeStyle;
let counter = 0;

let file = this.app.vault.getAbstractFileByPath(this.settings.excalibrainFilepath);
if(file && !(file instanceof TFile)) {
new Notice(`Please check settings. ExcaliBrain path (${this.settings.excalibrainFilepath}) points to a folder, not a file`);
return;
}
let counter = 0;
if(!file) {
file = await app.vault.create(this.settings.excalibrainFilepath,EMPTYBRAIN);
//an ugly temporary hack waiting for metadataCache to index the new file
Expand All @@ -143,6 +146,13 @@ export class Scene {
}
}
await this.leaf.openFile(file as TFile);
}

public async initilizeScene() {
this.disregardLeafChange = false;
const ea = this.ea;
const style = this.settings.baseNodeStyle;
let counter = 0;

ea.setView(this.leaf.view as any)
ea.clear();
Expand All @@ -154,7 +164,7 @@ export class Scene {
new Notice(`Error initializing Excalidraw view`);
return;
}
this.ea.targetView.hookServer = this.ea;
this.ea.registerThisAsViewEA();
this.ea.targetView.semaphores.saving = true; //disable saving by setting this Excalidraw flag (not published API)
ea.style.fontFamily = style.fontFamily;
ea.style.fontSize = style.fontSize;
Expand Down Expand Up @@ -216,8 +226,8 @@ export class Scene {
const children =centralPage.getChildren().filter(x=>x.page.path !==centralPage.path).slice(0,this.plugin.settings.maxItemCount);
const friends = centralPage.getFriends().filter(x=>x.page.path !== centralPage.path).slice(0,this.plugin.settings.maxItemCount);
const siblings = centralPage.getSiblings()
.filter(s => !(parents.some(p=>p.page.path === s.page.path) &&
children.some(c=>c.page.path === s.page.path) &&
.filter(s => !(parents.some(p=>p.page.path === s.page.path) ||
children.some(c=>c.page.path === s.page.path) ||
friends.some(f=>f.page.path === s.page.path)) &&
(s.page.path !== centralPage.path))
.slice(0,this.plugin.settings.maxItemCount);
Expand Down Expand Up @@ -458,19 +468,19 @@ export class Scene {
this.removeTimer = undefined;
}

if(isBoolean(this.ea.targetView?.linksAlwaysOpenInANewPane)) {
if(this.ea.targetView && isBoolean(this.ea.targetView.linksAlwaysOpenInANewPane)) {
this.ea.targetView.linksAlwaysOpenInANewPane = false;
}

if(this.ea.targetView?.excalidrawAPI) {
if(this.ea.targetView && this.ea.targetView.excalidrawAPI) {
try {
this.ea.targetView.semaphores.saving = false;
this.ea.targetView.excalidrawAPI.updateScene({appState:{viewModeEnabled:false}});
} catch {}
}

if(this.ea.targetView) {
this.ea.targetView.hookServer = null;
this.ea.deregisterThisAsViewEA();
}
this.searchBox?.terminate();
this.searchBox = undefined;
Expand Down
Loading

0 comments on commit 5742043

Please sign in to comment.