Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrychenzw committed Jun 10, 2024
1 parent 2b17306 commit cf452d1
Show file tree
Hide file tree
Showing 11 changed files with 752 additions and 143 deletions.
108 changes: 83 additions & 25 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Notice, Plugin } from "obsidian";
import { Plugin } from "obsidian";
import { t } from "src/lang/helper";
import { ZKNavigationSettngTab } from "src/settings/settings";
import { ZK_TABLE_TYPE, ZKTableView } from "src/view/tableView";
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";

export interface FoldNode{
graphID: string;
Expand Down Expand Up @@ -43,17 +44,28 @@ interface ZKNavigationSettings {
FoldNodeArr: FoldNode[];
RedDashLine: boolean;
zoomPanScaleArr:ZoomPanScale[];
CustomCreatedTime: string;
BranchTab: number;
HeightOfBranchGraph:number;
FileExtension:string; // "all" or ".md only"
SectionTab:number;
HeightOfFamilyGraph: number;
HeightOfInlinksGraph: number;
HeightOfOutlinksGraph: number;
DirectionOfBranchGraph: string,
DirectionOfFamilyGraph: string,
DirectionOfInlinksGraph: string,
DirectionOfOutlinksGraph: string,
DirectionOfBranchGraph: string;
DirectionOfFamilyGraph: string;
DirectionOfInlinksGraph: string;
DirectionOfOutlinksGraph: string;
BranchToolbra: boolean;
RandomIndex: boolean;
RandomMainNote: boolean;
TableView: boolean;
IndexButton: boolean;
MainNoteButton: boolean;
MainNoteButtonText: string;
SelectMainNote: string;
RefreshViews: boolean;
settingIcon:boolean;
}

//Default value for setting field
Expand All @@ -63,7 +75,7 @@ const DEFAULT_SETTINGS: ZKNavigationSettings = {
SelectIndex: '',
StartingPoint: 'father',
DisplayLevel: 'end',
NodeText: "id",
NodeText: "both",
FamilyGraphToggle: true,
InlinksGraphToggle: true,
OutlinksGraphToggle: true,
Expand All @@ -72,12 +84,13 @@ const DEFAULT_SETTINGS: ZKNavigationSettings = {
TitleField: '',
IDField: '',
Separator: ' ',
IndexButtonText: '📖index',
IndexButtonText: t('📖index'),
SuggestMode: 'fuzzySuggest',
FoldToggle: false,
FoldNodeArr: [],
RedDashLine:false,
zoomPanScaleArr:[],
CustomCreatedTime: '',
BranchTab: 0,
HeightOfBranchGraph: 530,
FileExtension: "md",
Expand All @@ -89,12 +102,22 @@ const DEFAULT_SETTINGS: ZKNavigationSettings = {
DirectionOfFamilyGraph: "LR",
DirectionOfInlinksGraph: "TB",
DirectionOfOutlinksGraph: "TB",

BranchToolbra: false,
RandomIndex: true,
RandomMainNote: true,
TableView: true,
IndexButton: true,
MainNoteButton: true,
MainNoteButtonText: t("Main notes"),
SelectMainNote: '',
RefreshViews: false,
settingIcon:true,
}

export default class ZKNavigationPlugin extends Plugin {

settings: ZKNavigationSettings;
tableArr:ZKNode[]

async loadSettings() {
this.settings = Object.assign(
Expand All @@ -114,36 +137,44 @@ export default class ZKNavigationPlugin extends Plugin {

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

this.addRibbonIcon("ghost", t("open zk-index-graph"), () => {
if(this.app.workspace.getLeavesOfType(ZK_INDEX_TYPE).length === 0){
this.openIndexView();
this.registerView(ZK_TABLE_TYPE, (leaf) => new ZKTableView(leaf, this, this.tableArr));

this.addRibbonIcon("ghost", t("open zk-index-graph"), async () => {
if(this.app.workspace.getLeavesOfType(ZK_INDEX_TYPE).length > 0){

await this.app.workspace.detachLeavesOfType(ZK_INDEX_TYPE);
}
this.openIndexView();

})

this.addRibbonIcon("network", t("open zk-local-graph"), () => {
if(this.app.workspace.getLeavesOfType(ZK_GRAPH_TYPE).length === 0){
this.openGraphView();
this.addRibbonIcon("network", t("open zk-local-graph"), async () => {
if(this.app.workspace.getLeavesOfType(ZK_GRAPH_TYPE).length > 0){
await this.app.workspace.detachLeavesOfType(ZK_GRAPH_TYPE);
}
this.openGraphView();
});

this.addCommand({
id: "zk-index-graph",
name: t("open zk-index-graph"),
callback:()=>{
if(this.app.workspace.getLeavesOfType(ZK_INDEX_TYPE).length === 0){
this.openIndexView();
callback:async ()=>{
if(this.app.workspace.getLeavesOfType(ZK_INDEX_TYPE).length > 0){

await this.app.workspace.detachLeavesOfType(ZK_INDEX_TYPE);
}
this.openIndexView();
}
});

this.addCommand({
id: "zk-local-graph",
name: t("open zk-local-graph"),
callback:()=>{
if(this.app.workspace.getLeavesOfType(ZK_GRAPH_TYPE).length === 0){
this.openGraphView();
callback: async ()=>{
if(this.app.workspace.getLeavesOfType(ZK_GRAPH_TYPE).length > 0){
await this.app.workspace.detachLeavesOfType(ZK_GRAPH_TYPE);
}
this.openGraphView();
}
});

Expand All @@ -158,10 +189,11 @@ export default class ZKNavigationPlugin extends Plugin {

async openIndexView() {

let leaf = this.app.workspace.getLeaf(false);
let leaf = this.app.workspace.getLeaf('tab');
if (leaf != null) {
await leaf.setViewState({
type: ZK_INDEX_TYPE
type: ZK_INDEX_TYPE,
active: true,
})
this.app.workspace.revealLeaf(leaf);
}
Expand All @@ -172,13 +204,39 @@ export default class ZKNavigationPlugin extends Plugin {
let leaf = this.app.workspace.getRightLeaf(false);
if (leaf != null) {
await leaf.setViewState({
type: ZK_GRAPH_TYPE
type: ZK_GRAPH_TYPE,
active: true,
})
this.app.workspace.revealLeaf(leaf);
}
}

async openTableView() {

if(this.app.workspace.getLeavesOfType(ZK_TABLE_TYPE).length > 0){

await this.app.workspace.detachLeavesOfType(ZK_TABLE_TYPE);

}

let leaf = this.app.workspace.getLeaf('tab');
if (leaf != null) {
await leaf.setViewState({
type: ZK_TABLE_TYPE,
active: true,
})
this.app.workspace.revealLeaf(leaf);
}
}

async refreshViews(){
if(this.app.workspace.getLeavesOfType(ZK_INDEX_TYPE).length > 0){
await this.app.workspace.detachLeavesOfType(ZK_INDEX_TYPE);
await this.openIndexView();
}

}

onunload() {

}
}
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.46",
"version": "0.0.47",
"minAppVersion": "1.5.7",
"description": "Visualize a Luhmann-style zettelkasten.",
"author": "terrychenzw",
Expand Down
32 changes: 30 additions & 2 deletions src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default {
'" "(blank)': '" "(blank)',
'"-"(hyphen)': '"-"(hyphen)',
'"_"(underscore)': '"_"(underscore)',
"ZK index file": "Index",
"Retrieval": "Retrieval",
"Indexes folder location": "Index files folder location",
"zk-index-graph-view": "zk-index-graph-view",
"Name of index button": "Name of index button",
Expand Down Expand Up @@ -49,7 +49,14 @@ export default {
'"BT": bottom to top': '"BT": bottom to top',
"direction of graph": "direction of graph",
"Detect file extensions": "Detect file extensions",

"Toolbar": "Toolbar",
"Open the icons(commands) in the branch graph.": "Open the icons(commands) on the index graph view.",
"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)",
"Specify a frontmatter field for time of note created time": "Specify a frontmatter field for the time of main note creation",

// indexView.ts
"Display from : ": "Display from : ",
"To : ": "To : ",
Expand All @@ -62,6 +69,15 @@ export default {
"title": "title",
"both": "both",
"Current index: ": "Current index:",
"random index": "random index",
"random main note": "random main note",
"❌Setting error: no folder or tag specified for main notes!": "❌Setting error: no folder or tag specified for main notes!",
"❌Setting error: no folder specified for index!": "❌Setting error: no folder specified for index!",
"Index: ": "Index: ",
"has no valid main note outlinks": "has no valid main note outlinks",
"table view": "table view",
"Current note: ": "Current note: ",
"settings": "open settings",

// localView.ts
"close relative": "close relative",
Expand All @@ -73,4 +89,16 @@ export default {
"open zk-local-graph": "open zk-local-graph",
"zk-local-graph": "zk-local-graph",
"zk-index-graph": "zk-index-graph",
"Main notes": "📄Main notes",
'📖index': '📖index',

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

//tableView.ts
"note's ID": "note's ID",
"note's title": "note's title",
"Time of creation": "Time of creation",

}
31 changes: 29 additions & 2 deletions src/lang/locale/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export default {
'" "(blank)': '" "(空格)',
'"-"(hyphen)': '"-"(横线)',
'"_"(underscore)': '"_"(下划线)',
"ZK index file": "关键词",
"Retrieval": "检索设置",
"Indexes folder location": "关键词文件存放位置",
"zk-index-graph-view": "关键词分支视图",
"Name of index button": "关键词按钮名称",
"Name of index button": "按钮名称",
"Suggest mode of index modal": "关键词查找模式",
"Keyword Order": "顺序查找",
"Fuzzy Suggest": "模糊查找",
Expand Down Expand Up @@ -48,6 +48,13 @@ export default {
'"TB": top to bottom': '"TB": 从上到下',
'"BT": bottom to top': '"BT": 从下到上',
"Detect file extensions": "限定出链的文件类型",
"Toolbar": "图标工具栏",
"Open the icons(commands) in the branch graph.":"打开分支视图的图标命令栏.",
"Index button": "关键词检索按钮",
"Main Notes button": "主笔记检索按钮",
"Name of main note button": "按钮名称",
"Custom created time(optional)": "主笔记创建时间(自定义字段)",
"Specify a frontmatter field for time of note created time": "指定一个属性字段作为主笔记的创建时间",

// indexView.ts
"Display from : ": "起点:",
Expand All @@ -61,6 +68,15 @@ export default {
"title": "标题",
"both": "ID + 标题",
"Current index: ": "当前关键词:",
"random index": "随机关键词",
"random main note": "随机主笔记",
"❌Setting error: no folder or tag specified for main notes!": "❌设置错误: 没有为主笔记指定文件夹或标签!",
"❌Setting error: no folder specified for index!": "❌设置错误: 没有为关键词指定文件夹!",
"Index: ": "关键词: ",
"has no valid main note outlinks": "没有包含有效主笔记链接",
"table view": "表格视图",
"Current note: ": "当前笔记: ",
"settings": "打开设置",

// localView.ts
"close relative": "邻近",
Expand All @@ -72,4 +88,15 @@ export default {
"open zk-local-graph": "打开局部关系视图",
"zk-index-graph": "关键词分支视图",
"zk-local-graph": "局部关系视图",
"Main notes": "📄主笔记",
'📖index': '📖关键词',

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

//tableView.ts
"note's ID": "笔记编号(ID)",
"note's title": "笔记标题",
"Time of creation": "创建时间",
}
9 changes: 5 additions & 4 deletions src/modal/indexModal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ZKNavigationPlugin from "main";
import { App, FuzzySuggestModal, Notice, SuggestModal, renderMatches } from "obsidian";
import { t } from "src/lang/helper";
import { ZKNode } from "src/view/indexView";

export interface ZKIndex {
Expand Down Expand Up @@ -32,15 +33,15 @@ export class indexModal extends SuggestModal<ZKIndex> {
const indexPath = this.plugin.settings.FolderOfIndexes;

if (indexPath == "") {
new Notice("Index folder not set!");
new Notice(t("Index folder not set!"));
} else {

// Get all indexes
const indexFiles = this.app.vault.getMarkdownFiles()
.filter(f => f.path.startsWith(indexPath + '/'));

if (indexFiles.length == 0) {
new Notice(`No index can be found by path "${indexPath}"`)
new Notice(`${t("No index can be found by path")} "${indexPath}"`)
}

// Get outlinks from index
Expand Down Expand Up @@ -114,15 +115,15 @@ export class indexFuzzyModal extends FuzzySuggestModal<ZKIndex> {
const indexPath = this.plugin.settings.FolderOfIndexes;

if (indexPath == "") {
new Notice("Index folder not set!");
new Notice(t("Index folder not set!"));
} else {

// Get all indexes
const indexFiles = this.app.vault.getMarkdownFiles()
.filter(f => f.path.startsWith(indexPath + '/'));

if (indexFiles.length == 0) {
new Notice(`No index can be found by path "${indexPath}"`)
new Notice(`${t("No index can be found by path")} "${indexPath}"`)
}

// Get outlinks from index
Expand Down
Loading

0 comments on commit cf452d1

Please sign in to comment.