-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
193 additions
and
157 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
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,96 @@ | ||
import * as vscode from 'vscode'; | ||
import * as path from 'path'; | ||
import { AsyncZettelViewTreeItem } from './AsyncZettelViewTreeItem'; | ||
import { IncomingIDMap } from './utils/IncomingIDMap'; | ||
import { MyLogger } from './utils/MyLogger'; | ||
|
||
export class IncomingZettelViewTreeDataProvider implements vscode.TreeDataProvider<AsyncZettelViewTreeItem> { | ||
private _onDidChangeTreeData: vscode.EventEmitter<undefined> = new vscode.EventEmitter<undefined>(); | ||
readonly onDidChangeTreeData: vscode.Event<undefined> = this._onDidChangeTreeData.event; | ||
|
||
private currentMarkdownFile: string | null = null; | ||
|
||
constructor(private workspaceRoot: string, private incomingIDMap: IncomingIDMap) { | ||
vscode.workspace.onDidOpenTextDocument((document) => { | ||
if (document.languageId === 'markdown') { | ||
this.currentMarkdownFile = document.fileName; | ||
this.refresh(); | ||
} | ||
}); | ||
vscode.window.onDidChangeActiveTextEditor(editor => { | ||
if (editor) { | ||
MyLogger.logMsg(`Editor changed: ${editor.document.fileName}`); | ||
if (editor.document.languageId === 'markdown') { | ||
this.currentMarkdownFile = editor.document.fileName; | ||
MyLogger.logMsg(`Current markdown file is ${this.currentMarkdownFile}`); | ||
this.refresh(); | ||
} else { | ||
MyLogger.logMsg(`Editor is not a markdown file.`); | ||
} | ||
} else { | ||
MyLogger.logMsg(`No active editor.`); | ||
} | ||
}); | ||
} | ||
|
||
|
||
//constructor(private workspaceRoot: string, private incomingLinksMap: IncomingLinksMap) { | ||
//vscode.window.onDidChangeActiveTextEditor(editor => { | ||
// if (editor && editor.document.languageId === 'markdown') { | ||
// this.currentMarkdownFile = editor.document.fileName; | ||
//MyLogger.logMsg(`Incoming Zettel View: Current markdown file is ${this.currentMarkdownFile}`); | ||
// this.refresh(); | ||
// } | ||
//}); | ||
//} | ||
|
||
refresh(): void { | ||
this._onDidChangeTreeData.fire(undefined); | ||
} | ||
|
||
getTreeItem(element: AsyncZettelViewTreeItem): vscode.TreeItem { | ||
return element; | ||
} | ||
|
||
async getChildren(element?: AsyncZettelViewTreeItem): Promise<AsyncZettelViewTreeItem[]> { | ||
if (!this.currentMarkdownFile) { | ||
vscode.window.showInformationMessage('Incoming Zettel View: No markdown file in focus'); | ||
MyLogger.logMsg('Incoming Zettel View: No markdown file in focus'); | ||
return []; | ||
} | ||
|
||
const id = path.basename(this.currentMarkdownFile, '.md'); | ||
const incomingIDs = this.incomingIDMap.getIncomingIDsFor(id); | ||
MyLogger.logMsg(`Incoming IDs for ${id}: ${JSON.stringify(incomingIDs)}`); // Add this log | ||
|
||
if (!incomingIDs || incomingIDs.size === 0) { | ||
vscode.window.showInformationMessage(`No incoming IDs for the file ${this.currentMarkdownFile}`); | ||
MyLogger.logMsg(`No incoming IDs for the file ${this.currentMarkdownFile}`); | ||
return []; | ||
} | ||
|
||
|
||
const items = await Promise.all(Array.from(incomingIDs).map(async (id: string) => { | ||
const pathname = path.join(this.workspaceRoot, `${id}.md`); | ||
const basename = `${id}.md`; | ||
const item = new AsyncZettelViewTreeItem( | ||
pathname, | ||
basename, | ||
vscode.TreeItemCollapsibleState.None, | ||
this.incomingIDMap, | ||
{ | ||
command: 'vscode.open', | ||
title: '', | ||
arguments: [vscode.Uri.file(pathname)], | ||
} | ||
); | ||
|
||
await item.isReady; | ||
return item; | ||
})); | ||
|
||
return items; | ||
} | ||
|
||
|
||
} |
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
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,34 @@ | ||
export class IncomingIDMap { | ||
private incomingIDs: Map<string, Set<string>>; | ||
|
||
constructor() { | ||
this.incomingIDs = new Map<string, Set<string>>(); | ||
} | ||
|
||
addID(sourceID: string, targetID: string) { | ||
if (!this.incomingIDs.has(targetID)) { | ||
this.incomingIDs.set(targetID, new Set<string>()); | ||
} | ||
|
||
this.incomingIDs.get(targetID)?.add(sourceID); | ||
} | ||
|
||
removeID(sourceID: string, targetID: string) { | ||
const incomingIDsForTarget = this.incomingIDs.get(targetID); | ||
if (incomingIDsForTarget) { | ||
incomingIDsForTarget.delete(sourceID); | ||
|
||
if (incomingIDsForTarget.size === 0) { | ||
this.incomingIDs.delete(targetID); | ||
} | ||
} | ||
} | ||
|
||
getIncomingIDsFor(targetID: string): Set<string> { | ||
return this.incomingIDs.get(targetID) || new Set<string>(); | ||
} | ||
|
||
// And so on | ||
} | ||
|
||
export const incomingIDMap = new IncomingIDMap(); |
Oops, something went wrong.