Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrychenzw committed Jul 21, 2024
1 parent c963e5f commit f286037
Show file tree
Hide file tree
Showing 13 changed files with 761 additions and 372 deletions.
132 changes: 89 additions & 43 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { FileView, Notice, Plugin, TFile, moment} from "obsidian";
import { FileView, Notice, Plugin, TFile} from "obsidian";
import { t } from "src/lang/helper";
import { ZKNavigationSettngTab } from "src/settings/settings";
import { ZKGraphView, ZK_GRAPH_TYPE } from "src/view/graphView";
import { ZKIndexView, ZK_INDEX_TYPE, ZK_NAVIGATION } from "src/view/indexView";
import { ZKIndexView, ZKNode, ZK_INDEX_TYPE, ZK_NAVIGATION } from "src/view/indexView";
import { ZK_OUTLINE_TYPE, ZKOutlineView } from "src/view/outlineView";
import { ZK_RECENT_TYPE, ZKRecentView } from "src/view/recentView";

export interface FoldNode{
graphID: string;
Expand Down Expand Up @@ -74,13 +76,15 @@ interface ZKNavigationSettings {
HistoryList: History[];
HistoryToggle: boolean;
HistoryMaxCount: number;
HistoryListShow: boolean;
ListTreeShow: boolean;
exportCanvas: boolean;
cardWidth: number;
cardHeight: number;
canvasFilePath: string;
siblingsOrder: string;
showAllToggle: boolean;
showAll: boolean;
play: boolean;
outlineLayer: number;
}

//Default value for setting field
Expand Down Expand Up @@ -116,11 +120,11 @@ const DEFAULT_SETTINGS: ZKNavigationSettings = {
DirectionOfFamilyGraph: "LR",
DirectionOfInlinksGraph: "TB",
DirectionOfOutlinksGraph: "TB",
BranchToolbra: false,
BranchToolbra: true,
RandomIndex: true,
RandomMainNote: true,
TableView: true,
IndexButton: false,
IndexButton: true,
MainNoteButton: true,
MainNoteButtonText: t("Main notes"),
SelectMainNote: '',
Expand All @@ -130,18 +134,22 @@ const DEFAULT_SETTINGS: ZKNavigationSettings = {
HistoryList: [],
HistoryToggle: true,
HistoryMaxCount: 20,
HistoryListShow: false,
ListTreeShow: false,
exportCanvas: true,
cardWidth: 400,
cardHeight: 240,
canvasFilePath: "",
siblingsOrder: "number",
siblingsOrder: "number",
showAll: false,
showAllToggle: true,
play: true,
outlineLayer: 2,
}

export default class ZKNavigationPlugin extends Plugin {

settings: ZKNavigationSettings;
MainNotes: ZKNode[];
tableArr: ZKNode[];
FileforLocaLgraph: string = "";
indexViewOffsetWidth: number = 0;
indexViewOffsetHeight: number = 0;
Expand Down Expand Up @@ -213,8 +221,7 @@ export default class ZKNavigationPlugin extends Plugin {

this.registerEvent(
this.app.workspace.on("file-menu", (menu, file, source) => {
console.log(source);


if (
!(
source === "more-options" ||
Expand Down Expand Up @@ -246,6 +253,10 @@ export default class ZKNavigationPlugin extends Plugin {
this.registerView(ZK_INDEX_TYPE, (leaf) => new ZKIndexView(leaf, this));

this.registerView(ZK_GRAPH_TYPE, (leaf) => new ZKGraphView(leaf, this));

this.registerView(ZK_OUTLINE_TYPE, (leaf) => new ZKOutlineView(leaf, this));

this.registerView(ZK_RECENT_TYPE, (leaf) => new ZKRecentView(leaf, this));

this.addRibbonIcon("ghost", t("open zk-index-graph"), async () => {

Expand Down Expand Up @@ -280,37 +291,7 @@ export default class ZKNavigationPlugin extends Plugin {
id: "zk-index-graph-by-file",
name: t("reveal current file in zk-index-graph"),
callback: async ()=>{
let filePath = this.app.workspace.getActiveViewOfType(FileView)?.file?.path

if(filePath && filePath.endsWith(".md")){

let indexFlag:boolean = false;

if(this.settings.FolderOfIndexes !== ""){
if(filePath.startsWith(this.settings.FolderOfIndexes)){
indexFlag = true;
this.settings.SelectIndex = filePath;
this.settings.SelectMainNote = "";
this.settings.zoomPanScaleArr = [];
this.settings.BranchTab = 0;
this.settings.FoldNodeArr = [];
this.RefreshIndexViewFlag = true;
await this.openIndexView();
}
}

if(!indexFlag){
this.settings.SelectMainNote = filePath;
this.settings.SelectIndex = "";
this.settings.zoomPanScaleArr = [];
this.settings.BranchTab = 0;
this.settings.FoldNodeArr = [];
this.RefreshIndexViewFlag = true;
await this.openIndexView();
}

return;
}
await this.revealFileInIndexView();
}
})

Expand All @@ -319,7 +300,7 @@ export default class ZKNavigationPlugin extends Plugin {
{
defaultMod:true,
display:ZK_NAVIGATION,
});
});

}

Expand Down Expand Up @@ -349,13 +330,78 @@ export default class ZKNavigationPlugin extends Plugin {
type:ZK_GRAPH_TYPE,
active:true,
});

}
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(ZK_GRAPH_TYPE)[0]
);
this.app.workspace.trigger("zk-navigation:refresh-local-graph");
}

async openOutlineView() {
if(this.app.workspace.getLeavesOfType(ZK_OUTLINE_TYPE).length === 0){
await this.app.workspace.getRightLeaf(false)?.setViewState({
type:ZK_OUTLINE_TYPE,
active:true,
});
}
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(ZK_OUTLINE_TYPE)[0]
);
this.app.workspace.trigger("zk-navigation:refresh-outline-view");

}

async openRecentView() {
if(this.app.workspace.getLeavesOfType(ZK_RECENT_TYPE).length === 0){
await this.app.workspace.getRightLeaf(false)?.setViewState({
type:ZK_RECENT_TYPE,
active:true,
});
}
this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(ZK_RECENT_TYPE)[0]
);
this.app.workspace.trigger("zk-navigation:refresh-recent-view");

}

async clearShowingSettings(BranchTab:number=0){
this.settings.zoomPanScaleArr = [];
this.settings.BranchTab = BranchTab;
this.settings.FoldNodeArr = [];
}

async revealFileInIndexView(){

let filePath = this.app.workspace.getActiveViewOfType(FileView)?.file?.path

if(filePath && filePath.endsWith(".md")){

let indexFlag:boolean = false;

if(this.settings.FolderOfIndexes !== ""){
if(filePath.startsWith(this.settings.FolderOfIndexes)){
indexFlag = true;
this.settings.SelectIndex = filePath;
this.settings.SelectMainNote = "";
this.clearShowingSettings();
this.RefreshIndexViewFlag = true;
await this.openIndexView();
}
}

if(!indexFlag){
this.settings.SelectMainNote = filePath;
this.settings.SelectIndex = "";
this.clearShowingSettings();
this.RefreshIndexViewFlag = true;
await this.openIndexView();
}
return;
}
}

onunload() {
this.saveData(this.settings);
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "zettelkasten-navigation",
"name": "zettelkasten navigation",
"version": "0.0.53",
"version": "1.0.0",
"minAppVersion": "1.5.7",
"description": "Visualize a Luhmann-style zettelkasten.",
"author": "terrychenzw",
Expand Down
6 changes: 4 additions & 2 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default {
"Index button": "Index retrieval button",
"Main Notes button": "Main notes retrieval button",
"Name of main note button": "Name of main note button",
"Custom created time(optional)": "Custom created time(used in table view)",
"Custom created time(optional)": "Custom created time(used in table view and animation)",
"Specify a frontmatter field for time of note created time": "Specify a frontmatter field for the time of main note creation",
"History List": "recent retrieval",
"And set the list length": "Set the max length",
Expand Down Expand Up @@ -95,6 +95,8 @@ export default {
"export to canvas": "export to canvas",
"select a main note": "select a main note",
"select an index": "select an index",
"all trees": "all trees",
"growing animation": "start timelapse animation",

// localView.ts
"close relative": "close relative",
Expand All @@ -113,7 +115,7 @@ export default {
"reveal current file in zk-index-graph": "reveal current file in zk-index-graph",

//indexModal.ts
"Index folder not set!": "Index folder not set!",
"Index folder not set!": "❌Setting error: Index folder not set!",
"No index can be found by path": "No index can be found by path",

//tableView.ts
Expand Down
6 changes: 4 additions & 2 deletions src/lang/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default {
"next": "向下一层",
"end": "最后一层",
"title": "标题",
"both": "ID + 标题",
"both": "id + 标题",
"Current index: ": "当前关键词:",
"random index": "随机关键词",
"random main note": "随机主笔记",
Expand All @@ -95,6 +95,8 @@ export default {
"export to canvas": "导出到白板",
"select a main note": "选择一个主笔记",
"select an index": "选择一个关键词",
"all trees": "所有树",
"growing animation": "播放分支生长动画",

// localView.ts
"close relative": "邻近",
Expand All @@ -113,7 +115,7 @@ export default {
"reveal current file in zk-index-graph": "在关键词分支视图显示当前文件",

//indexModal.ts
"Index folder not set!": "关键词文件夹没有设置!",
"Index folder not set!": "❌设置错误: 关键词文件夹没有设置!",
"No index can be found by path": "指定文件夹找不到任何关键词:",

//tableView.ts
Expand Down
14 changes: 13 additions & 1 deletion src/modal/expandGraphModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,21 @@ export class expandGraphModal extends Modal {
link.textContent = nodeArr[i].getText();
nodeArr[i].textContent = "";
nodeArr[i].appendChild(link);
nodeArr[i].addEventListener("click", (event: MouseEvent) => {
nodeGArr[i].addEventListener("click", (event: MouseEvent) => {
if(event.ctrlKey){
this.app.workspace.openLinkText("", path, 'tab');
}else if(event.shiftKey){
this.plugin.FileforLocaLgraph = path;
this.plugin.openGraphView();
}else if(event.altKey){
let mainNote = this.plugin.MainNotes.find(n=>n.file.path == path);

if(mainNote){
this.plugin.clearShowingSettings();
this.plugin.settings.SelectMainNote = mainNote.file.path;
this.app.workspace.trigger("zk-navigation:refresh-index-graph");
}

}else{
this.app.workspace.openLinkText("",path)
}
Expand Down
Loading

0 comments on commit f286037

Please sign in to comment.