Skip to content

Commit

Permalink
Added setting to enable and disable new note function
Browse files Browse the repository at this point in the history
  • Loading branch information
gravypower committed Apr 20, 2021
1 parent 08b9cc2 commit 8349ced
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/QuickLinksPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {

let hints: Hint[] = [];

if(prefix) {
if(response.allowNewNotes && prefix) {
hints.push(NewNoteHint(prefix, false));
hints.push(NewNoteHint(prefix, true));
}
Expand Down
29 changes: 25 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ import { ContentScriptType, SettingItem, SettingItemType } from 'api/types';
const NUM_RESULTS = 21;
const FOLDERS_REFRESH_INTERVAL = 6000;
const SETTING_SHOW_FOLDERS = 'showFolders';
const SETTING_ALLOW_NEW_NOTES = 'allowNewNotes';

let showFolders = false;
let allowNewNotes = false;
let folders = {};

async function onShowFolderSettingChanged() {
showFolders = await joplin.settings.value(SETTING_SHOW_FOLDERS);
if (showFolders) {
refreshFolderList();
await refreshFolderList();
}
}

async function onAllowNewNotesSettingChanged() {
allowNewNotes = await joplin.settings.value(SETTING_ALLOW_NEW_NOTES);
}

async function refreshFolderList() {
folders = await getFolders();
setTimeout(() => {
Expand Down Expand Up @@ -72,13 +78,28 @@ async function initSettings() {
label: 'Show Notebooks',
} as SettingItem);

await joplin.settings.registerSetting(SETTING_ALLOW_NEW_NOTES, {
public: true,
section: SECTION,
type: SettingItemType.Bool,
value: allowNewNotes,
label: 'Allow new Notes',
} as SettingItem);

await onShowFolderSettingChanged();

await onAllowNewNotesSettingChanged();

await joplin.settings.onChange(change => {
const idx = change.keys.indexOf(SETTING_SHOW_FOLDERS);
if (idx >= 0) {
const showFoldersIdx = change.keys.indexOf(SETTING_SHOW_FOLDERS);
if (showFoldersIdx >= 0) {
onShowFolderSettingChanged();
}

const allowNewNotesIdx = change.keys.indexOf(SETTING_ALLOW_NEW_NOTES);
if (allowNewNotesIdx >= 0) {
onAllowNewNotesSettingChanged();
}
});
}

Expand All @@ -105,7 +126,7 @@ joplin.plugins.register({
folder: folders[n.parent_id],
};
});
return { notes: res, showFolders: showFolders };
return { notes: res, showFolders: showFolders, allowNewNotes: allowNewNotes};
}
else if(message.command === 'createNote')
{
Expand Down

0 comments on commit 8349ced

Please sign in to comment.