From b3328e2e44aa84b3bdae140e0ed381d761323d9b Mon Sep 17 00:00:00 2001 From: Matt Bidewell Date: Sun, 4 Oct 2020 17:30:53 +0100 Subject: [PATCH 1/4] Added option menu --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index ff639ff..ab614d6 100644 --- a/package.json +++ b/package.json @@ -192,8 +192,14 @@ "type": "boolean", "default": true, "description": "Show file name under annotation" + }, + "saveLocation": { + "type":"string", + "default": "", + "description": "Set a save location. Default is VSCode Global path" } } + } }, "scripts": { From 99a68cc2450142fa35a4d39a5319aa8394c70f95 Mon Sep 17 00:00:00 2001 From: Matt Bidewell Date: Sun, 4 Oct 2020 17:33:17 +0100 Subject: [PATCH 2/4] Added new configuration option --- src/configuration.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 1eb5b1b..8598f9e 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -11,7 +11,7 @@ export const getAnnotationFilePath = (): string => { export const initializeStorageLocation = (location: string) => { if (location) { - storageLocation = location; + storageLocation = path.resolve(location); if (!fs.existsSync(storageLocation)) { fs.mkdirSync(storageLocation, { recursive: true }); } @@ -26,13 +26,17 @@ export const initializeStorageLocation = (location: string) => { export interface Configuration { showFileName: boolean; + saveLocation: string; } export const getConfiguration = (): Configuration => { const configuration = vscode.workspace.getConfiguration(); const showFileName = configuration.get('showFileName'); + const saveLocation = configuration.get('saveLocation'); + const config: Configuration = { - showFileName: typeof showFileName === 'boolean' ? showFileName : false + showFileName: typeof showFileName === 'boolean' ? showFileName : false, + saveLocation: typeof saveLocation === 'string' ? saveLocation : '' }; return config; From 769780ff60cf72240e8a8156708d637a8fadba76 Mon Sep 17 00:00:00 2001 From: Matt Bidewell Date: Sun, 4 Oct 2020 17:33:44 +0100 Subject: [PATCH 3/4] Added log statement for location save point --- src/configuration.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/configuration.ts b/src/configuration.ts index 8598f9e..946ad0e 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -12,6 +12,7 @@ export const getAnnotationFilePath = (): string => { export const initializeStorageLocation = (location: string) => { if (location) { storageLocation = path.resolve(location); + console.log('Save location is: ' + storageLocation); if (!fs.existsSync(storageLocation)) { fs.mkdirSync(storageLocation, { recursive: true }); } From 248394bf7c0493eb8300f7076b13a257f5d0daf2 Mon Sep 17 00:00:00 2001 From: Matt Bidewell Date: Sun, 4 Oct 2020 17:35:46 +0100 Subject: [PATCH 4/4] Added ability to set location to save storage. --- src/extension.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 3b54496..6a12fb8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,12 +4,17 @@ import * as fs from 'fs'; import { addNote, addPlainNote } from './note-db'; import { generateMarkdownReport } from './reporting'; import { NotesTree, TreeActions } from './notes-tree'; -import { initializeStorageLocation, getAnnotationFilePath } from './configuration'; +import { initializeStorageLocation, getAnnotationFilePath, getConfiguration } from './configuration'; export function activate(context: vscode.ExtensionContext) { console.log('Extension "code-annotation" is now active!'); - initializeStorageLocation(context.globalStoragePath); + const configuration = getConfiguration(); + + // if path is '', use global. + const storagePath = !configuration.saveLocation ? context.globalStoragePath : configuration.saveLocation; + + initializeStorageLocation(storagePath); const tree = new NotesTree(); const treeActions = new TreeActions(tree);