extension: only insert date on current week

This commit is contained in:
Vincent Batts 2017-02-20 14:08:12 -05:00
parent 1a7945b5fe
commit 8c51dfaca1
2 changed files with 11 additions and 6 deletions

View File

@ -42,7 +42,7 @@ function activate(context) {
vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir); vscode.window.showErrorMessage("next-note: failed to make directory: "+basedir);
return; return;
} }
openNote(basedir +"/"+ formatWeekFilename(currentWeek())); openNote(basedir +"/"+ formatWeekFilename(currentWeek()), true);
})); }));
context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenNextWeek', function () { context.subscriptions.push(vscode.commands.registerTextEditorCommand('extension.nextNoteOpenNextWeek', function () {
@ -68,13 +68,18 @@ exports.deactivate = deactivate;
* opens filepath in the current window, creating the file if needed * opens filepath in the current window, creating the file if needed
* *
* @param {String} filepath is the path of the new note file * @param {String} filepath is the path of the new note file
* @param {Boolean} insertDate whether to insert the date stamp on creation
* @return {undefined} * @return {undefined}
*/ */
function openNote(filepath) { function openNote(filepath, insertDate) {
fs.access(filepath, fs.constants.R_OK | fs.constants.W_OK, (err) => { fs.access(filepath, fs.constants.R_OK | fs.constants.W_OK, (err) => {
if (err) { if (err) {
try { try {
fs.writeFileSync(filepath, dateLine()); if (insertDate) {
fs.writeFileSync(filepath, dateLine());
} else {
fs.writeFileSync(filepath, "");
}
} catch (e) { } catch (e) {
vscode.window.showErrorMessage("next-note: failed to create "+ filepath); vscode.window.showErrorMessage("next-note: failed to create "+ filepath);
console.error(e); console.error(e);
@ -94,7 +99,7 @@ function openNote(filepath) {
* @returns {String} * @returns {String}
*/ */
function getBasedir() { function getBasedir() {
var basedir = process.env["NOTEDIR"]; var basedir = process.env["NOTEDR"];
if (!basedir) { if (!basedir) {
basedir = process.env["HOME"]+"/Notes"; basedir = process.env["HOME"]+"/Notes";

View File

@ -25,7 +25,7 @@
"commands": [ "commands": [
{ {
"command": "extension.nextNoteOpenPreviousWeek", "command": "extension.nextNoteOpenPreviousWeek",
"title": "NextNote: Open Current Week" "title": "NextNote: Open Previous Week"
}, },
{ {
"command": "extension.nextNoteOpenCurrentWeek", "command": "extension.nextNoteOpenCurrentWeek",
@ -33,7 +33,7 @@
}, },
{ {
"command": "extension.nextNoteOpenNextWeek", "command": "extension.nextNoteOpenNextWeek",
"title": "NextNote: Open Current Week" "title": "NextNote: Open Next Week"
}, },
{ {
"command": "extension.nextNoteInsertDate", "command": "extension.nextNoteInsertDate",