diff --git a/src/Scene.ts b/src/Scene.ts index b1cfcdb..133d8bd 100644 --- a/src/Scene.ts +++ b/src/Scene.ts @@ -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; @@ -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); } diff --git a/src/Settings.ts b/src/Settings.ts index 10dffbd..452c2c4 100644 --- a/src/Settings.ts +++ b/src/Settings.ts @@ -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; @@ -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() { @@ -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(); @@ -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", @@ -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, diff --git a/src/lang/locale/en.ts b/src/lang/locale/en.ts index 9b90a31..bd06732 100644 --- a/src/lang/locale/en.ts +++ b/src/lang/locale/en.ts @@ -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.
Tagnames should start with # and may be incomplete. i.e. #book will match #books, #book/fiction, etc.
" + + "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 " + diff --git a/src/main.ts b/src/main.ts index 4fd03c7..54c241c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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; } @@ -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())