mirror of
https://github.com/daledesilva/obsidian_google-keep-import.git
synced 2026-07-22 07:50:23 +00:00
Added all settings to settings panel
This commit is contained in:
parent
82d238e796
commit
c43bb14ab3
5 changed files with 263 additions and 38 deletions
|
|
@ -77,7 +77,7 @@ async function getImportFolder(vault: Vault, settings: PluginSettings): Promise<
|
|||
|
||||
// Find the folder if it exists
|
||||
for(let i=0; i<root.children.length; i++) {
|
||||
if(root.children[i].path == settings.folderNames.imports) {
|
||||
if(root.children[i].path == settings.folderNames.notes) {
|
||||
importFolder = root.children[i] as TFolder;
|
||||
break;
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ async function getImportFolder(vault: Vault, settings: PluginSettings): Promise<
|
|||
|
||||
// Create the folder if it doesn't exist
|
||||
if(importFolder === undefined) {
|
||||
await vault.createFolder(settings.folderNames.imports);
|
||||
await vault.createFolder(settings.folderNames.notes);
|
||||
importFolder = await getImportFolder(vault, settings)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,21 @@
|
|||
export enum createdDateTypes {
|
||||
googleKeep = 'Google Keep creation date',
|
||||
import = 'Obsidian import date',
|
||||
};
|
||||
|
||||
export interface PluginSettings {
|
||||
folderNames: {
|
||||
imports: string,
|
||||
notes: string,
|
||||
attachments: string
|
||||
},
|
||||
createdDate: createdDateTypes,
|
||||
importArchived: boolean,
|
||||
importTrashed: boolean,
|
||||
addColorTags: boolean,
|
||||
addPinnedTags: boolean,
|
||||
addAttachmentTags: boolean,
|
||||
addArchivedTags: boolean,
|
||||
addTrashedTags: boolean,
|
||||
tagNames: {
|
||||
colorPrepend: string,
|
||||
isPinned: string,
|
||||
|
|
@ -10,6 +23,4 @@ export interface PluginSettings {
|
|||
isArchived: string,
|
||||
isTrashed: string,
|
||||
},
|
||||
importArchived: boolean,
|
||||
importTrashed: boolean,
|
||||
}
|
||||
19
src/main.ts
19
src/main.ts
|
|
@ -1,17 +1,25 @@
|
|||
import { fileSyntax } from 'esbuild-sass-plugin/lib/utils';
|
||||
import { App, DataWriteOptions, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, TFile, TFolder, Vault } from 'obsidian';
|
||||
import { PluginSettings } from './logic/types';
|
||||
import { createdDateTypes, PluginSettings } from './logic/types';
|
||||
import { StartImportModal } from './modals/import-modal/import-modal';
|
||||
import { SampleSettingTab } from './tabs/settings-tab/settings-tab';
|
||||
|
||||
|
||||
|
||||
|
||||
const DEFAULT_SETTINGS: PluginSettings = {
|
||||
export const DEFAULT_SETTINGS: PluginSettings = {
|
||||
folderNames: {
|
||||
imports: 'Keep Imports',
|
||||
attachments: 'Attachments'
|
||||
notes: 'Keep Imports',
|
||||
attachments: 'Keep Imports/Attachments'
|
||||
},
|
||||
createdDate: createdDateTypes.googleKeep,
|
||||
importArchived: true,
|
||||
importTrashed: false,
|
||||
addColorTags: true,
|
||||
addPinnedTags: true,
|
||||
addAttachmentTags: true,
|
||||
addArchivedTags: true,
|
||||
addTrashedTags: true,
|
||||
tagNames: {
|
||||
colorPrepend: '#Keep/Colour/',
|
||||
isPinned: '#Keep/Pinned',
|
||||
|
|
@ -19,8 +27,6 @@ const DEFAULT_SETTINGS: PluginSettings = {
|
|||
isArchived: '#Keep/Archived',
|
||||
isTrashed: '#Keep/Trashed',
|
||||
},
|
||||
importArchived: true,
|
||||
importTrashed: false,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -31,6 +37,7 @@ export default class KeepPlugin extends Plugin {
|
|||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
console.log('this.settings', this.settings);
|
||||
|
||||
|
||||
this.addCommand({
|
||||
|
|
|
|||
|
|
@ -43,6 +43,37 @@ If your plugin does not need CSS, delete this file.
|
|||
|
||||
|
||||
|
||||
.uo_setting {
|
||||
&.is-disabled {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Increase the width of text inputs and drop down to their own line on small windows.
|
||||
// But not toggles
|
||||
.uo_setting:not(.mod-toggle) {
|
||||
flex-wrap: wrap;
|
||||
|
||||
.setting-item-info {
|
||||
padding-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.setting-item-info {
|
||||
flex: 1 0 30ch;
|
||||
}
|
||||
.setting-item-control {
|
||||
flex: 1 30ch;
|
||||
input, select {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.uo_progress-bar {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
import MyPlugin from "src/main";
|
||||
import { createdDateTypes } from "src/logic/types";
|
||||
import MyPlugin, { DEFAULT_SETTINGS } from "src/main";
|
||||
|
||||
|
||||
|
||||
|
|
@ -16,43 +17,218 @@ export class SampleSettingTab extends PluginSettingTab {
|
|||
|
||||
containerEl.empty();
|
||||
|
||||
containerEl.createEl('h2', {text: 'Settings for my awesome plugin.'});
|
||||
containerEl.createEl('h2', {text: 'Basics'});
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Note import folder')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.folderNames.notes);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.folderNames.notes = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Attachment import folder')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.folderNames.attachments);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.folderNames.attachments = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Note creation date')
|
||||
.setDesc('Should the imported not have a creation date set to the same date it was created on in Google Keep, or should it change to the date it was imported into Obsidian on?')
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption(createdDateTypes.googleKeep, createdDateTypes.googleKeep);
|
||||
dropdown.addOption(createdDateTypes.import, createdDateTypes.import);
|
||||
dropdown.setValue(this.plugin.settings.createdDate)
|
||||
dropdown.onChange(async (value) => {
|
||||
this.plugin.settings.createdDate = value as createdDateTypes;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
|
||||
containerEl.createEl('hr');
|
||||
containerEl.createEl('h2', {text: 'Optional imports'});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Import archived notes')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.importArchived)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.importArchived = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Import trashed notes')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.importTrashed)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.importTrashed = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
containerEl.createEl('hr');
|
||||
containerEl.createEl('h2', {text: 'Tags'});
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Colour tags')
|
||||
.setDesc('Add a tag representing the color of the note in Google Keep.')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.addColorTags)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.addColorTags = value;
|
||||
await this.plugin.saveSettings();
|
||||
colorPrefixInput.setDisabled(!value);
|
||||
});
|
||||
})
|
||||
let colorPrefixInput = new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setClass('uo_setting-child')
|
||||
.setDesc('Text to prepend to each colour tag.')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.tagNames.colorPrepend);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.tagNames.colorPrepend = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
.setDisabled(!this.plugin.settings.addColorTags)
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Hide "Open Other Vault" button')
|
||||
.setDesc('This will hide the button at the bottom left that returns you to the Vault Selector screen. This is mostly useful for mobile users that find this button disruptive to flow.')
|
||||
.addToggle(value => value
|
||||
.setValue(this.plugin.settings.hideOpenVaultButton)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.hideOpenVaultButton = !value;
|
||||
.setClass('uo_setting')
|
||||
.setName('Pinned tags')
|
||||
.setDesc('Add a tag if the note was pinned in Google Keep.')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.addPinnedTags)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.addPinnedTags = value;
|
||||
await this.plugin.saveSettings();
|
||||
}));
|
||||
pinnedTagInput.setDisabled(!value);
|
||||
});
|
||||
})
|
||||
let pinnedTagInput = new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setClass('uo_setting-child')
|
||||
.setDesc('Pinned tag.')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.tagNames.isPinned);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.tagNames.isPinned = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
.setDisabled(!this.plugin.settings.addPinnedTags)
|
||||
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .setName("Name")
|
||||
// .addText((text) =>
|
||||
// text.onChange((value) => {
|
||||
// this.result = value
|
||||
// }));
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Attachment tags')
|
||||
.setDesc('Add a tag if the note has an attachment.')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.addAttachmentTags)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.addAttachmentTags = value;
|
||||
await this.plugin.saveSettings();
|
||||
attachmentTagInput.setDisabled(!value);
|
||||
});
|
||||
})
|
||||
let attachmentTagInput = new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setClass('uo_setting-child')
|
||||
.setDesc('Attachment tag.')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.tagNames.hasAttachment);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.tagNames.hasAttachment = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
.setDisabled(!this.plugin.settings.addAttachmentTags)
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .addColorPicker(color => {});
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .addExtraButton(btn => {});
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Archived tags')
|
||||
.setDesc('Add a tag if the note was archived in Google Keep (If imported).')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.addArchivedTags)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.addArchivedTags = value;
|
||||
await this.plugin.saveSettings();
|
||||
archivedTagInput.setDisabled(!value);
|
||||
});
|
||||
})
|
||||
let archivedTagInput = new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setClass('uo_setting-child')
|
||||
.setDesc('Archived tag.')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.tagNames.isArchived);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.tagNames.isArchived = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
.setDisabled(!this.plugin.settings.addArchivedTags)
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .addMomentFormat(test => {})
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .addSearch(test => {});
|
||||
new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setName('Trashed tags')
|
||||
.setDesc('Add a tag if the note was trashed in Google Keep (If imported).')
|
||||
.addToggle(toggle => {
|
||||
toggle.setValue(this.plugin.settings.addTrashedTags)
|
||||
toggle.onChange(async (value) => {
|
||||
this.plugin.settings.addTrashedTags = value;
|
||||
await this.plugin.saveSettings();
|
||||
trashedTag.setDisabled(!value);
|
||||
});
|
||||
})
|
||||
let trashedTag = new Setting(containerEl)
|
||||
.setClass('uo_setting')
|
||||
.setClass('uo_setting-child')
|
||||
.setDesc('Trashed tag.')
|
||||
.addText((text) => {
|
||||
text.setValue(this.plugin.settings.tagNames.isTrashed);
|
||||
text.onChange(async (value) => {
|
||||
this.plugin.settings.tagNames.isTrashed = value;
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
})
|
||||
.setDisabled(!this.plugin.settings.addTrashedTags)
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .addSlider(test => {});
|
||||
|
||||
// new Setting(contentEl)
|
||||
// .addTextArea(test => {});
|
||||
containerEl.createEl('hr');
|
||||
|
||||
|
||||
new Setting(containerEl)
|
||||
.addButton( (button) => {
|
||||
button.setButtonText('Reset settings');
|
||||
button.setWarning();
|
||||
button.onClick(async () => {
|
||||
this.plugin.settings = JSON.parse( JSON.stringify(DEFAULT_SETTINGS) );
|
||||
await this.plugin.saveSettings();
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue