Skip to content

Commit

Permalink
- Fixed: formatting and code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesb committed Jun 20, 2021
1 parent 7065e92 commit a4c844d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
15 changes: 14 additions & 1 deletion data.json
Original file line number Diff line number Diff line change
@@ -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}
{
"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
}
44 changes: 23 additions & 21 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -264,7 +266,7 @@ export default class IW extends Plugin {
subscribeToEvents() {
this.app.workspace.onLayoutReady(() => {
this.addSearchButton();
this.autoAddNewNotesOnCreate();
this.autoAddNewNotesOnCreate();
});

this.registerEvent(
Expand Down
18 changes: 9 additions & 9 deletions src/views/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
}
}

0 comments on commit a4c844d

Please sign in to comment.