update the setting manager init new view param

This commit is contained in:
Hananoshika Yomaru 2023-12-30 10:43:54 -08:00 committed by erhazan
parent 075ce49f0e
commit caffbbb5c1
6 changed files with 25 additions and 23 deletions

View file

@ -78,9 +78,12 @@ export class GlobalGraph3dView extends Graph3dView<GlobalGraphSettingManager, Gl
}
protected onReady(): void {
super.onReady();
// first we need to create the force graph
this.forceGraph = new ForceGraph(this as typeof this.forceGraph.view, this.plugin.globalGraph);
// then we need to init the setting manager
this.settingManager.initNewView(true);
this.settingManager.initNewView({
collapsed: true,
});
}
}

View file

@ -60,7 +60,13 @@ export abstract class Graph3dView<
// since setting manager need to be initialized first before the force graph
// in the graph 3d view constructor, we need to initialize it in the in the onReady function
this.forceGraph = undefined as unknown as ForceGraph<Graph3dView<M, ItemView>>;
}
/**
* 1. need to initialize force graph here but this class doesn't know how to initialize it
* 2. graph setting manager need to init a view here
*/
protected onReady(): void {
// register event on event bus
const parent = this.getParent();
parent.registerEvent(
@ -82,12 +88,6 @@ export abstract class Graph3dView<
);
}
/**
* 1. need to initialize force graph here but this class doesn't know how to initialize it
* 2. graph setting manager need to init a view here
*/
protected abstract onReady(): void;
/**
* get the current force graph object
*/

View file

@ -189,9 +189,12 @@ export class LocalGraph3dView extends Graph3dView<LocalGraphSettingManager, Loca
}
protected onReady() {
super.onReady();
type LocalGraph3dView = typeof this.forceGraph.view;
this.forceGraph = new ForceGraph(this as LocalGraph3dView, getNewLocalGraph(this.plugin));
this.settingManager.initNewView(true);
this.settingManager.initNewView({
collapsed: true,
});
}
public handleFileChange = (file: TFile) => {

View file

@ -74,14 +74,14 @@ export class PostProcessorGraph3dView extends Graph3dView<
}
onReady(): void {
super.onReady();
// first we need to create the force graph
this.forceGraph = new ForceGraph(
this as typeof this.forceGraph.view,
getNewLocalGraph(this.plugin)
);
// post process graph will not have 3d graph
// setting manager init view
this.settingManager.initNewView(true);
// init event handler on parent
this.parent.registerEvent(this.eventBus.on("open-node-preview", (node: Node) => {}));
// this.settingManager.initNewView(true);
}
}

View file

@ -89,7 +89,12 @@ export abstract class GraphSettingManager<
/**
* this function will initialize a new view for setting and then append it to the current graph view
*/
initNewView(collapsed = false) {
initNewView(
config: {
collapsed?: boolean;
} = {}
) {
const { collapsed = false } = config;
// check if the contentEl of the graph View already contains the containerEl of setting manager, if not add it
if (!this.graphView.contentEl.contains(this.containerEl)) {
this.graphView.contentEl.appendChild(this.containerEl);
@ -228,7 +233,7 @@ export abstract class GraphSettingManager<
PluginSettingManager.getNewSetting(this.graphView.graphType);
});
this.initNewView(false);
this.initNewView();
}
public applySettings(newSetting: SavedSetting["setting"]) {
@ -243,7 +248,7 @@ export abstract class GraphSettingManager<
//
newSetting;
});
this.initNewView(false);
this.initNewView();
}
/**

View file

@ -16,15 +16,6 @@ export class PostProcessorGraphSettingManager extends GraphSettingManager<
this.currentSetting = new State(PluginSettingManager.getNewSetting(GraphType.postProcessor));
}
// we need to override this because the underlying update method will update plugin setting
// instead of updating the plugin setting, we need to update the value in side the codeblock
updateCurrentSettings(
updateFunc: (setting: State<MarkdownPostProcessorGraphSettings>) => void,
shouldUpdateGraphView?: boolean
): MarkdownPostProcessorGraphSettings {
return this.currentSetting.value;
}
static new(parentView: PostProcessorGraph3dView) {
const settingManager = new PostProcessorGraphSettingManager(parentView);
settingManager.onReady();