diff --git a/src/components/settings-groups/settings-groups.ts b/src/components/settings-groups/settings-groups.ts index b61ca64..9086644 100644 --- a/src/components/settings-groups/settings-groups.ts +++ b/src/components/settings-groups/settings-groups.ts @@ -2,7 +2,7 @@ import { Setting } from "obsidian"; import { folderPathSanitize } from "src/logic/string-processes"; import GoogleKeepImportPlugin from "src/main"; import { ConfirmationModal } from "src/modals/confirmation-modal/confirmation-modal"; -import { CreatedDateTypes } from "src/types/plugin-settings"; +import { CreatedDateTypes, MappingPresets } from "src/types/plugin-settings"; /////////////////// @@ -295,29 +295,10 @@ export class CharMappingGroup { constructor(containerEl: HTMLElement, plugin: GoogleKeepImportPlugin) { containerEl.createEl('h2', {text: 'Character Mapping'}); - - containerEl.createEl('h3', {text: 'Invalid characters'}); - containerEl.createEl('p', {text: 'Some characters are invalid when used in file or folder names on certain operating systems. They will therefore be converted to the following characters.'}); - - containerEl.createEl('p', {text: 'You can customise this mapping or selected from a preset.'}); - - for(let k=0; k { - text.setValue(plugin.settings.invalidChars[k].replacement); - text.inputEl.addEventListener('blur', async (e) => { - const value = text.getValue(); - plugin.settings.invalidChars[k].replacement = value; - text.setValue(value); - await plugin.saveSettings(); - }); - }) - } + containerEl.createEl('p', {text: 'Some characters don\'t work so well in file or folder names on certain operating systems. They will therefore be converted according to the following mapping settings.'}); containerEl.createEl('h3', {text: 'Problem characters'}); - containerEl.createEl('p', {text: 'Some characters are valid but will prevent Obsidian links to them working properly. They will therefore be converted to the following characters.'}); + containerEl.createEl('p', {text: 'While these won\'t break the imports, they will create issues with links from other files—So are best avoided.'}); for(let k=0; k { + dropdown.addOption(MappingPresets.all, 'Fix for all'); + dropdown.addOption(MappingPresets.apple, "Apple"); + dropdown.addOption(MappingPresets.android, "Android"); + dropdown.addOption(MappingPresets.windows, "Windows"); + dropdown.addOption(MappingPresets.linux, "Linux"); + dropdown.setValue(MappingPresets.all); + dropdown.onChange(async (value) => { + // plugin.settings.createdDate = value as CreatedDateTypes; + await plugin.saveSettings(); + }); + }) + + for(let k=0; k { + text.setValue(plugin.settings.invalidChars[k].replacement); + text.inputEl.addEventListener('blur', async (e) => { + const value = text.getValue(); + plugin.settings.invalidChars[k].replacement = value; + text.setValue(value); + await plugin.saveSettings(); + }); + }) + } } diff --git a/src/main.ts b/src/main.ts index 38d4613..09f2cac 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,6 +7,46 @@ import MastodonIcon from 'src/assets/mastodon'; /////////////////// /////////////////// +export const invalidChars_allPreset = [ + { char: '*', replacement: '+' }, + { char: '"', replacement: "'" }, + { char: '\\', replacement: '-' }, + { char: '/', replacement: '-' }, + { char: '<', replacement: '(' }, + { char: '>', replacement: ')' }, + { char: ':', replacement: '_' }, + { char: '|', replacement: '_' }, + { char: '?', replacement: '' }, +]; + + +export const invalidChars_appleAndroidPreset = [ + { char: '*', replacement: '+' }, + { char: '\\', replacement: '-' }, + { char: '/', replacement: '-' }, + { char: ':', replacement: '_' }, + { char: '|', replacement: '_' }, + { char: '?', replacement: '' }, +]; + + +export const invalidChars_windowsPreset = [ + { char: '*', replacement: '+' }, + { char: '"', replacement: "'" }, + { char: '\\', replacement: '-' }, + { char: '/', replacement: '-' }, + { char: '<', replacement: '(' }, + { char: '>', replacement: ')' }, + { char: ':', replacement: '_' }, + { char: '|', replacement: '_' }, + { char: '?', replacement: '' }, +]; + + +export const invalidChars_linuxPreset = [ + { char: '/', replacement: '-' }, +]; + /** * The default settings that a new install starts with @@ -34,45 +74,6 @@ export const DEFAULT_SETTINGS: PluginSettings = { isArchived: '#Keep/Archived', isTrashed: '#Keep/Trashed', }, - // These characters aren't valid in the filepath or name on different operating systems. - invalidChars: [ - { - char: '*', - replacement: '+' - }, - { - char: '"', - replacement: "'" - }, - { - char: '\\', - replacement: '-' - }, - { - char: '/', - replacement: '-' - }, - { - char: '<', - replacement: '(' - }, - { - char: '>', - replacement: ')' - }, - { - char: ':', - replacement: '_' - }, - { - char: '|', - replacement: '_' - }, - { - char: '?', - replacement: '' - }, - ], // These characters will work infilepath and name but will break linkability. problemChars: [ { @@ -95,10 +96,14 @@ export const DEFAULT_SETTINGS: PluginSettings = { char: '|', replacement: '_' }, - ] + ], + // These characters aren't valid in the filepath or name on different operating systems. + invalidChars: JSON.parse( JSON.stringify(invalidChars_allPreset) ), } + + /** * The base plugin class initialised by Obsidian on launch */ diff --git a/src/types/plugin-settings.ts b/src/types/plugin-settings.ts index 1a03bc4..b86160e 100644 --- a/src/types/plugin-settings.ts +++ b/src/types/plugin-settings.ts @@ -6,6 +6,14 @@ export enum CreatedDateTypes { import = 'Obsidian import date', }; +export enum MappingPresets { + all = 'all', + windows = 'windows', + apple = 'apple', + android = 'android', + linux = 'linux', +}; + export interface CharMap { char: string, replacement: string, @@ -34,6 +42,6 @@ export interface PluginSettings { isArchived: string, isTrashed: string, }, - invalidChars: Array, problemChars: Array, + invalidChars: Array, }