generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
237 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import ExcaliBrain from "src/main"; | ||
|
||
export class ToggleButton { | ||
private button: HTMLButtonElement; | ||
|
||
constructor( | ||
plugin: ExcaliBrain, | ||
private getVal: ()=>boolean, | ||
setVal: (val:boolean)=>void, | ||
wrapper: HTMLElement, | ||
options: { | ||
display: string, | ||
tooltip: string | ||
}) { | ||
this.button = wrapper.createEl("button", { | ||
cls: "excalibrain-button", | ||
}); | ||
this.button.createSpan({text: options.display}) | ||
this.button.ariaLabel = options.tooltip; | ||
|
||
this.setColor(); | ||
|
||
this.button.onclick = () => { | ||
setVal(!getVal()); | ||
plugin.saveSettings(); | ||
this.setColor(); | ||
plugin.scene?.reRender(); | ||
} | ||
} | ||
|
||
setColor() { | ||
if(this.getVal()) { | ||
this.button.removeClass("off"); | ||
this.button.addClass("on"); | ||
return; | ||
} | ||
this.button.removeClass("on"); | ||
this.button.addClass("off"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { TFile } from "obsidian"; | ||
import { ExcalidrawElement } from "obsidian-excalidraw-plugin"; | ||
import { ToggleButton } from "src/Components/ToggleButton"; | ||
import { t } from "src/lang/helpers"; | ||
import ExcaliBrain from "src/main"; | ||
import { splitFolderAndFilename } from "src/utils/fileUtils"; | ||
import { FileSuggest } from "./FileSuggester"; | ||
|
||
export class ToolsPanel { | ||
private wrapperDiv: HTMLDivElement; | ||
private buttons: ToggleButton[] = []; | ||
|
||
constructor( | ||
private contentEl: HTMLElement, | ||
private plugin: ExcaliBrain | ||
) { | ||
contentEl.addClass("excalibrain-contentEl"); | ||
this.wrapperDiv = this.contentEl.createDiv(); | ||
this.wrapperDiv.addClass("excalibrain-search-wrapper"); | ||
|
||
//------ | ||
//search | ||
//------ | ||
const inputEl = this.wrapperDiv.createEl("input",{ | ||
type: "text", | ||
cls: "excalibrain-searchinput" | ||
}); | ||
inputEl.ariaLabel = t("SEARCH_IN_VAULT"); | ||
inputEl.oninput = () => { | ||
const file = app.vault.getAbstractFileByPath(inputEl.value); | ||
if(file && file instanceof TFile) { | ||
this.plugin.scene?.renderGraphForFile(inputEl.value); | ||
inputEl.value = file.basename; | ||
} | ||
} | ||
new FileSuggest( | ||
this.plugin.app, | ||
inputEl, | ||
this.plugin | ||
); | ||
|
||
|
||
//------------ | ||
//Edit drawing | ||
//------------ | ||
const saveAsDrawingButton = this.wrapperDiv.createEl("button", { | ||
cls: "excalibrain-button", | ||
text: "✏" | ||
}); | ||
saveAsDrawingButton.ariaLabel = t("OPEN_DRAWING"); | ||
saveAsDrawingButton.onclick = () => { | ||
const elements = this.plugin.EA.getExcalidrawAPI().getSceneElements() as ExcalidrawElement[]; | ||
const appState = this.plugin.EA.getExcalidrawAPI().getAppState(); | ||
const ea = this.plugin.EA; //window.ExcalidrawAutomate; | ||
ea.reset(); | ||
ea.canvas.viewBackgroundColor = appState.viewBackgroundColor; | ||
ea.canvas.theme = "light"; | ||
elements.forEach(el=>ea.elementsDict[el.id] = el); | ||
ea.create({ | ||
filename: `ExcaliBrain Snapshot - ${splitFolderAndFilename(this.plugin.scene.centralPagePath).basename}`, | ||
onNewPane:true | ||
}); | ||
} | ||
|
||
//------------ | ||
//Attachments | ||
//------------ | ||
this.buttons.push( | ||
new ToggleButton( | ||
this.plugin, | ||
()=>this.plugin.settings.showAttachments, | ||
(val:boolean)=>this.plugin.settings.showAttachments = val, | ||
this.wrapperDiv, | ||
{ | ||
display: "📎", | ||
tooltip: t("SHOW_HIDE_ATTACHMENTS") | ||
} | ||
) | ||
) | ||
|
||
//------------ | ||
//Virtual | ||
//------------ | ||
this.buttons.push( | ||
new ToggleButton( | ||
this.plugin, | ||
()=>this.plugin.settings.showVirtualNodes, | ||
(val:boolean)=>this.plugin.settings.showVirtualNodes = val, | ||
this.wrapperDiv, | ||
{ | ||
display: "∅", | ||
tooltip: t("SHOW_HIDE_VIRTUAL") | ||
} | ||
) | ||
) | ||
|
||
//------------ | ||
//Inferred | ||
//------------ | ||
this.buttons.push( | ||
new ToggleButton( | ||
this.plugin, | ||
()=>this.plugin.settings.showInferredNodes, | ||
(val:boolean)=>this.plugin.settings.showInferredNodes = val, | ||
this.wrapperDiv, | ||
{ | ||
display: "🤔", | ||
tooltip: t("SHOW_HIDE_INFERRED") | ||
} | ||
) | ||
) | ||
|
||
//------------ | ||
//Alias | ||
//------------ | ||
this.buttons.push( | ||
new ToggleButton( | ||
this.plugin, | ||
()=>this.plugin.settings.renderAlias, | ||
(val:boolean)=>this.plugin.settings.renderAlias = val, | ||
this.wrapperDiv, | ||
{ | ||
display: "🧥", | ||
tooltip: t("SHOW_HIDE_ALIAS") | ||
} | ||
) | ||
) | ||
|
||
this.contentEl.appendChild(this.wrapperDiv); | ||
|
||
} | ||
|
||
rerender() { | ||
this.buttons.forEach(b=>b.setColor()); | ||
} | ||
|
||
terminate() { | ||
if(this.wrapperDiv) { | ||
try{ | ||
this.contentEl?.removeChild(this.wrapperDiv); | ||
} catch{} | ||
this.wrapperDiv = null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.