From a4c844de70eadfa756d574de7ae0d264dd133b90 Mon Sep 17 00:00:00 2001 From: jamesb Date: Sun, 20 Jun 2021 12:41:52 +0100 Subject: [PATCH] - Fixed: formatting and code style. --- data.json | 15 ++++++++++++- src/main.ts | 44 ++++++++++++++++++++------------------- src/views/settings-tab.ts | 18 ++++++++-------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/data.json b/data.json index 8027a8e..6f555bd 100644 --- a/data.json +++ b/data.json @@ -1 +1,14 @@ -{"defaultPriorityMin":17,"defaultPriorityMax":64,"queueFolderPath":"IW-Queues","queueFileName":"Tasks.md","defaultQueueType":"simple","skipAddNoteWindow":true,"autoAddNewNotes":true,"vimMode":false,"defaultPriority":30,"queueFilePath":"queue.md","defaultAFactor":2,"defaultInterval":1} \ No newline at end of file +{ + "defaultPriorityMin": 17, + "defaultPriorityMax": 64, + "queueFolderPath": "IW-Queues", + "queueFileName": "Tasks.md", + "defaultQueueType": "simple", + "skipAddNoteWindow": true, + "autoAddNewNotes": true, + "vimMode": false, + "defaultPriority": 30, + "queueFilePath": "queue.md", + "defaultAFactor": 2, + "defaultInterval": 1 +} diff --git a/src/main.ts b/src/main.ts index d286fab..2848d15 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,7 +15,7 @@ import { FileUtils } from "./helpers/file-utils"; import { BulkAdderModal } from "./views/bulk-adding"; import { BlockUtils } from "./helpers/block-utils"; import { FuzzyNoteAdder } from "./views/fuzzy-note-adder"; -import {MarkdownTableRow} from "./markdown" +import { MarkdownTableRow } from "./markdown"; export default class IW extends Plugin { settings: IWSettings; @@ -58,30 +58,32 @@ export default class IW extends Plugin { } randomWithinInterval(min: number, max: number) { - return Math.floor(Math.random() * (max - min + 1) + min) + return Math.floor(Math.random() * (max - min + 1) + min); } autoAddNewNotesOnCreate() { - if (this.settings.autoAddNewNotes){ - this.autoAddNewNotesOnCreateEvent = this.app.vault.on('create', (file) => { - if (!(file instanceof TFile) || file.extension !== "md"){ - return; - } - let link = this.files.toLinkText(file); - let min = this.settings.defaultPriorityMin; - let max = this.settings.defaultPriorityMax; - let priority = this.randomWithinInterval(min, max) - let row = new MarkdownTableRow(link, priority, "") - LogTo.Console("Auto adding new note to default queue: " + link) - this.queue.addNotesToQueue(row); - }); - } - else { - if (this.autoAddNewNotesOnCreateEvent) { - this.app.vault.offref(this.autoAddNewNotesOnCreateEvent); - this.autoAddNewNotesOnCreateEvent = undefined; + if (this.settings.autoAddNewNotes) { + this.autoAddNewNotesOnCreateEvent = this.app.vault.on( + "create", + (file) => { + if (!(file instanceof TFile) || file.extension !== "md") { + return; } + let link = this.files.toLinkText(file); + let min = this.settings.defaultPriorityMin; + let max = this.settings.defaultPriorityMax; + let priority = this.randomWithinInterval(min, max); + let row = new MarkdownTableRow(link, priority, ""); + LogTo.Console("Auto adding new note to default queue: " + link); + this.queue.addNotesToQueue(row); } + ); + } else { + if (this.autoAddNewNotesOnCreateEvent) { + this.app.vault.offref(this.autoAddNewNotesOnCreateEvent); + this.autoAddNewNotesOnCreateEvent = undefined; + } + } } async getSearchLeafView() { @@ -264,7 +266,7 @@ export default class IW extends Plugin { subscribeToEvents() { this.app.workspace.onLayoutReady(() => { this.addSearchButton(); - this.autoAddNewNotesOnCreate(); + this.autoAddNewNotesOnCreate(); }); this.registerEvent( diff --git a/src/views/settings-tab.ts b/src/views/settings-tab.ts index 065a8b7..43de877 100644 --- a/src/views/settings-tab.ts +++ b/src/views/settings-tab.ts @@ -156,14 +156,14 @@ export class IWSettingsTab extends PluginSettingTab { // Auto add new Setting(containerEl) - .setName("Auto Add New Notes?") - .setDesc("Automatically add new notes to the default queue?") - .addToggle((comp) => { - comp.setValue(settings.autoAddNewNotes).onChange((value) => { - settings.autoAddNewNotes = value - this.plugin.saveData(settings); - this.plugin.autoAddNewNotesOnCreate(); - }) - }) + .setName("Auto Add New Notes?") + .setDesc("Automatically add new notes to the default queue?") + .addToggle((comp) => { + comp.setValue(settings.autoAddNewNotes).onChange((value) => { + settings.autoAddNewNotes = value; + this.plugin.saveData(settings); + this.plugin.autoAddNewNotesOnCreate(); + }); + }); } }