diff --git a/src/extension.ts b/src/extension.ts index abdd952..ad4c4cb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,41 +5,9 @@ import * as fs from 'fs'; import * as path from 'path'; import * as readline from 'readline'; -// This is my rough and ready approach to logging: create -// a static logger class that sets an output channel for messages -// Until I add someone else's logger to the list of dependencies, -// you'll have to put up with self-contained code. - -class myLogger { - static readonly myExtension = "Zettel View"; - static readonly logOutputChannel = vscode.window.createOutputChannel(this.myExtension); - static logMsg(msg : string): void { - const now = new Date(); - const timestamp = now.toLocaleString(); - this.logOutputChannel.appendLine(`[${timestamp}] ${msg}`); - } -} +import { myLogger } from './util'; +import { id } from './util'; // IDregex object -class IDregex { - // The ID regex is a configuration contribution point, with a default value - private _re: RegExp; // save the compiled regex - private _regex: string; // save the pattern as a string - constructor() { - const regex = vscode.workspace.getConfiguration().get('zettelView.regex'); - this._regex = regex as string; - if (!this._regex) { - this._regex = '^# ((\\w{1,4}\\.){2,}\\d\\w{3}) (.+)$'; // set the default regex if undefined - vscode.window.showInformationMessage(`No regex found in settings. Using default: ${this._regex}`); - } - this._re = new RegExp(this._regex); - } - - get re(): RegExp { return this._re; } - get regex(): string { return this._regex; } -} - -// sadly, a global variable for the compiled RegExp is needed by each -const id = new IDregex(); class AsyncZettelViewTreeItem extends vscode.TreeItem { //public label: string; This is public in TreeItem! @@ -159,10 +127,20 @@ class ZettelViewTreeDataProvider implements vscode.TreeDataProvider 0)) + ? vscode.workspace.workspaceFolders[0].uri.fsPath : undefined; + if (workspaceRoot) { const provider = new ZettelViewTreeDataProvider(workspaceRoot); vscode.window.registerTreeDataProvider('zettelView', provider); + + // In case we would like to operate on the tree view... + // this is a redesign + // this.ftpViewer = vscode.window.createTreeView('ftpExplorer', { treeDataProvider }); + vscode.commands.registerCommand('zettelView.refreshEntry', () => provider.refresh()); } } diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..9dbfe42 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,38 @@ + +import * as vscode from 'vscode'; + +// This is my rough and ready approach to logging: create +// a static logger class that sets an output channel for messages +// Until I add someone else's logger to the list of dependencies, +// you'll have to put up with self-contained code. + +export class myLogger { + static readonly myExtension = "Zettel View"; + static readonly logOutputChannel = vscode.window.createOutputChannel(this.myExtension); + static logMsg(msg : string): void { + const now = new Date(); + const timestamp = now.toLocaleString(); + this.logOutputChannel.appendLine(`[${timestamp}] ${msg}`); + } +} + +export class IDregex { + // The ID regex is a configuration contribution point, with a default value + private _re: RegExp; // save the compiled regex + private _regex: string; // save the pattern as a string + constructor() { + const regex = vscode.workspace.getConfiguration().get('zettelView.regex'); + this._regex = regex as string; + if (!this._regex) { + this._regex = '^# ((\\w{1,4}\\.){2,}\\d\\w{3}) (.+)$'; // set the default regex if undefined + vscode.window.showInformationMessage(`No regex found in settings. Using default: ${this._regex}`); + } + this._re = new RegExp(this._regex); + } + + get re(): RegExp { return this._re; } + get regex(): string { return this._regex; } +} + +// sadly, an object for compiled RegExp is needed by each ZettelViewTreeItem +export const id = new IDregex();