Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed May 1, 2022
1 parent 5742043 commit 57e0ae6
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 62 deletions.
2 changes: 0 additions & 2 deletions src/Scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ 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 @@ -42,7 +41,6 @@ export class Scene {
}

public async initialize() {
log("initialize");
await this.initilizeScene();
this.searchBox = new SearchBox((this.leaf.view as TextFileView).contentEl,this.plugin);
}
Expand Down
149 changes: 92 additions & 57 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ const addStylesheet = (stylesheet: string, classname: string) => {
export class ExcaliBrainSettingTab extends PluginSettingTab {
plugin: ExcaliBrain;
ea: ExcalidrawAutomate;
private hierarchy: string = null;
private dirty:boolean = false;
private demoNode: Node;
private demoImg: HTMLImageElement;
Expand All @@ -145,28 +144,6 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
constructor(app: App, plugin: ExcaliBrain) {
super(app, plugin);
this.plugin = plugin;
this.ea = getEA();

const page = new Page(
"This is a demo node that is 46 characters long",
null,
this.plugin
)
const page2 = new Page(
"Dummy child",
null,
this.plugin
)
page.addChild(page2,RelationType.DEFINED);

this.demoNode = new Node({
page,
isInferred: false,
isCentral: false,
isSibling: false,
friendGateOnLeft: false
})
this.demoNode.ea = this.ea;
}

async updateDemoImg() {
Expand Down Expand Up @@ -810,6 +787,29 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {

async display() {
await this.plugin.loadSettings(); //in case sync loaded changed settings in the background
this.ea = getEA();

//initialize sample
const page = new Page(
"This is a demo node that is 46 characters long",
null,
this.plugin
)
const page2 = new Page(
"Dummy child",
null,
this.plugin
)
page.addChild(page2,RelationType.DEFINED);
this.demoNode = new Node({
page,
isInferred: false,
isCentral: false,
isSibling: false,
friendGateOnLeft: false
})
this.demoNode.ea = this.ea;

const { containerEl } = this;
this.containerEl.empty();

Expand Down Expand Up @@ -987,9 +987,75 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {
this.plugin.settings.backgroundColor
)

let nodeStylesDropdown: DropdownComponent;
let nodeStyleDiv: HTMLDivElement;
const nodeDropdownOnChange = (value:string) => {
nodeStyleDiv.empty();
const nodeStyle = this.plugin.nodeStyles[value];
this.nodeSettings(
nodeStyleDiv,
nodeStyle.display,
nodeStyle.style,
nodeStyle.allowOverride,
nodeStyle.getInheritedStyle()
)
this.demoNodeStyle = nodeStyle;
this.updateDemoImg();
}

const taglist = new Setting(containerEl)
.setName(t("TAGLIST_NAME"))
.setDesc(t("TAGLIST_DESC"))
.addTextArea((text)=> {
text.inputEl.style.height = "200px";
text.inputEl.style.width = "100%";
text
.setValue(this.plugin.settings.tagStyleList.join(", "))
.onChange(value => {
const tagStyles = this.plugin.settings.tagNodeStyles
const nodeStyles = this.plugin.nodeStyles;
value = value.replaceAll("\n"," ");
const tags = value.split(",").map(s=>s.trim());
this.plugin.settings.tagStyleList = tags;
Object.keys(tagStyles).forEach(key => {
if(!tags.contains(key)) {
delete tagStyles[key];
delete nodeStyles[key];
}
});
tags.forEach(tag => {
if(!Object.keys(tagStyles).contains(tag)) {
tagStyles[tag] = {};
nodeStyles[tag] = {
style: tagStyles[tag],
allowOverride: true,
userStyle: true,
display: tag,
getInheritedStyle: () => this.plugin.settings.baseNodeStyle
}
}
});
const selectedItem = nodeStylesDropdown.getValue();
for(let i=nodeStylesDropdown.selectEl.options.length-1;i>=0;i--) {
nodeStylesDropdown.selectEl.remove(i);
}
Object.entries(nodeStyles).forEach(item=>{
nodeStylesDropdown.addOption(item[0],item[1].display)
})
if(nodeStyles[selectedItem]) {
nodeStylesDropdown.setValue(selectedItem);
} else {
nodeStylesDropdown.setValue("base");
nodeDropdownOnChange("base");
}
this.dirty = true;
})
})

taglist.descEl.style.maxWidth="400px";
const nodeStylesWrapper = containerEl.createDiv({cls:"setting-item"});
const dropodownWrapper = nodeStylesWrapper.createDiv({cls:"setting-item-info"});
const nodeStylesDropdown = new DropdownComponent(dropodownWrapper);
nodeStylesDropdown = new DropdownComponent(dropodownWrapper);

const toggleLabel = nodeStylesWrapper.createDiv({
text: "Show inherited",
Expand All @@ -1015,44 +1081,13 @@ export class ExcaliBrainSettingTab extends PluginSettingTab {

this.demoImg = containerEl.createEl("img",{cls: "excalibrain-settings-demoimg"});

const nodeStyleDiv = containerEl.createDiv({
nodeStyleDiv = containerEl.createDiv({
cls: "excalibrain-setting-nodestyle-section"
});
removeStylesheet(HIDE_DISABLED_STYLE);
nodeStylesDropdown
.setValue("base")
.onChange(value => {
nodeStyleDiv.empty();
let nodeStyle = this.plugin.nodeStyles[value];
if(!nodeStyle) {
this.plugin.nodeStyles[value] = {
style: {},
allowOverride: true,
userStyle: true,
display: value,
getInheritedStyle: ()=>{
return {
...this.plugin.settings.baseNodeStyle,
//...this.plugin.settings.inferredLinkStyle,
//...this.plugin.settings.virtualNodeStyle,
//...this.plugin.settings.centralNodeStyle,
//...this.plugin.settings.siblingNodeStyle,
//...this.plugin.settings.attachmentNodeStyle
}
}
}
nodeStyle = this.plugin.nodeStyles[value];
}
this.nodeSettings(
nodeStyleDiv,
nodeStyle.display,
nodeStyle.style,
nodeStyle.allowOverride,
nodeStyle.getInheritedStyle()
)
this.demoNodeStyle = nodeStyle;
this.updateDemoImg();
})
.onChange(nodeDropdownOnChange)
const nodeStyle = this.plugin.nodeStyles["base"];
this.nodeSettings(
nodeStyleDiv,
Expand Down
4 changes: 4 additions & 0 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export default {
"All other styles may have partial definitions. e.g. You may add a prefix and override the base node-background color in the tag-based style, " +
"override the font color in the inferred-node style and set the border stroke style to dotted in the virtual-node style.",
CANVAS_BGCOLOR: "Canvas color",
TAGLIST_NAME: "Formatted tags",
TAGLIST_DESC: "You can specify special formatting rules for Nodes based on tags. If multiple tags are present on the page the first matching a specification " +
"will be used. <br>Tagnames should start with <mark>#</mark> and may be incomplete. i.e. <code>#book</code> will match #books, #book/fiction, etc.<br>" +
"Enter a comma separated list of tags here, then select from the dropdown list to change the formatting.",
MAX_ITEMCOUNT_DESC: "Maximum node count",
MAX_ITEMCOUNT_NAME: "Maximum number of nodes to display in a given area of the layout." +
"i.e. the maximum number of parents, the maximum number of children, the maximum number of friends, and " +
Expand Down
5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ export default class ExcaliBrain extends Plugin {
this.scene = null;
} else {
const leaf = this.getBrainLeaf();
this.scene = new Scene(this,true,this.getBrainLeaf());
this.scene = new Scene(this,true,leaf);
//@ts-ignore
if(leaf.view && leaf.view.file && leaf.view.file.path == this.settings.excalibrainFilepath) {
if(leaf && leaf.view && leaf.view.file && leaf.view.file.path == this.settings.excalibrainFilepath) {
this.scene.initialize();
return;
}
Expand Down Expand Up @@ -300,7 +300,6 @@ export default class ExcaliBrain extends Plugin {
errorlog({where: "ExcaliBrain.start()", fn: this.start, message: "ExcaliBrain did not load. Aborting after 5000ms of trying"});
return;
}
log("start");
this.stop();
if(!leaf) {
this.scene = new Scene(this,true,this.getBrainLeaf())
Expand Down

0 comments on commit 57e0ae6

Please sign in to comment.