Changed overwrite confirmation to only appear on new notes
Overwrite confirmation should only appear if a new note is created, not when updating the metadata for an existing note.
This commit is contained in:
parent
9a521a174f
commit
46952218de
2 changed files with 10 additions and 8 deletions
|
|
@ -512,6 +512,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
// look if file already exists and ask if it should be overwritten
|
// look if file already exists and ask if it should be overwritten
|
||||||
const file = this.app.vault.getAbstractFileByPath(filePath);
|
const file = this.app.vault.getAbstractFileByPath(filePath);
|
||||||
if (file) {
|
if (file) {
|
||||||
|
if (!options.isUpdating) {
|
||||||
const shouldOverwrite = await new Promise<boolean>(resolve => {
|
const shouldOverwrite = await new Promise<boolean>(resolve => {
|
||||||
new ConfirmOverwriteModal(this.app, fileName, resolve).open();
|
new ConfirmOverwriteModal(this.app, fileName, resolve).open();
|
||||||
});
|
});
|
||||||
|
|
@ -519,7 +520,7 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
if (!shouldOverwrite) {
|
if (!shouldOverwrite) {
|
||||||
throw new Error('MDB | file creation cancelled by user');
|
throw new Error('MDB | file creation cancelled by user');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await this.app.vault.delete(file);
|
await this.app.vault.delete(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -574,9 +575,9 @@ export default class MediaDbPlugin extends Plugin {
|
||||||
console.debug(`MDB | newMediaTypeModel after merge`, newMediaTypeModel);
|
console.debug(`MDB | newMediaTypeModel after merge`, newMediaTypeModel);
|
||||||
|
|
||||||
if (onlyMetadata) {
|
if (onlyMetadata) {
|
||||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachFile: activeFile, folder: activeFile.parent ?? undefined, openNote: true });
|
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachFile: activeFile, folder: activeFile.parent ?? undefined, openNote: true, isUpdating: true });
|
||||||
} else {
|
} else {
|
||||||
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachTemplate: true, folder: activeFile.parent ?? undefined, openNote: true });
|
await this.createMediaDbNoteFromModel(newMediaTypeModel, { attachTemplate: true, folder: activeFile.parent ?? undefined, openNote: true, isUpdating: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,6 +193,7 @@ export interface CreateNoteOptions {
|
||||||
attachFile?: TFile;
|
attachFile?: TFile;
|
||||||
openNote?: boolean;
|
openNote?: boolean;
|
||||||
folder?: TFolder;
|
folder?: TFolder;
|
||||||
|
isUpdating?: boolean; // New property
|
||||||
}
|
}
|
||||||
|
|
||||||
export function migrateObject<T extends object>(object: T, oldData: any, defaultData: T): void {
|
export function migrateObject<T extends object>(object: T, oldData: any, defaultData: T): void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue