feat: update command menu for mobile rendering

This commit is contained in:
Nightwish2710 2025-08-18 14:28:23 +07:00
parent 03b6de9db7
commit 203d9f4119

View file

@ -298,55 +298,55 @@ export class Commands {
}
}
const addFolderNoteActions = (menu: Menu) => {
if (file instanceof TFile) {
const addFolderNoteActions = (menu: Menu) => {
if (file instanceof TFile) {
menu.addItem((item) => {
item.setTitle('Create folder note');
item.setIcon('edit');
item.onClick(async () => {
if (!folder) return;
let newPath = folder.path + '/' + file.basename;
if (folder.path === '' || folder.path === '/') {
newPath = file.basename;
}
if (this.plugin.app.vault.getAbstractFileByPath(newPath)) {
return new Notice('Folder already exists');
}
const automaticallyCreateFolderNote =
this.plugin.settings.autoCreate;
this.plugin.settings.autoCreate = false;
this.plugin.saveSettings();
await this.plugin.app.vault.createFolder(newPath);
const newFolder = this.plugin.app.vault
.getAbstractFileByPath(newPath);
if (!(newFolder instanceof TFolder)) return;
await createFolderNote(
this.plugin,
newFolder.path,
true,
'.' + file.extension,
false,
file,
);
this.plugin.settings.autoCreate = automaticallyCreateFolderNote;
this.plugin.saveSettings();
});
if (!folder) return;
let newPath = folder.path + '/' + file.basename;
if (folder.path === '' || folder.path === '/') {
newPath = file.basename;
}
if (this.plugin.app.vault.getAbstractFileByPath(newPath)) {
return new Notice('Folder already exists');
}
const automaticallyCreateFolderNote =
this.plugin.settings.autoCreate;
this.plugin.settings.autoCreate = false;
this.plugin.saveSettings();
await this.plugin.app.vault.createFolder(newPath);
const newFolder = this.plugin.app.vault
.getAbstractFileByPath(newPath);
if (!(newFolder instanceof TFolder)) return;
await createFolderNote(
this.plugin,
newFolder.path,
true,
'.' + file.extension,
false,
file,
);
this.plugin.settings.autoCreate = automaticallyCreateFolderNote;
this.plugin.saveSettings();
});
});
if (getFolderPathFromString(file.path) === '') return;
if (!(folder instanceof TFolder)) return;
if (!(folder instanceof TFolder)) return;
if (folder.path === '' || folder.path === '/') return;
if (folder.path === '' || folder.path === '/') return;
menu.addItem((item) => {
menu.addItem((item) => {
item.setTitle(`Turn into folder note for ${folder?.name}`);
item.setIcon('edit');
item.onClick(() => {
if (!folder || !(folder instanceof TFolder)) return;
const folderNote = getFolderNote(this.plugin, folder.path);
turnIntoFolderNote(this.plugin, file, folder, folderNote);
});
if (!folder || !(folder instanceof TFolder)) return;
const folderNote = getFolderNote(this.plugin, folder.path);
turnIntoFolderNote(this.plugin, file, folder, folderNote);
});
});
}
@ -355,32 +355,32 @@ export class Commands {
const excludedFolder = getExcludedFolder(this.plugin, file.path, false);
const detachedExcludedFolder = getDetachedFolder(this.plugin, file.path);
if (excludedFolder && !excludedFolder.hideInSettings) {
if (excludedFolder && !excludedFolder.hideInSettings) {
// I'm not sure if I'm ever going to add this because of the possibility that a folder got more than one excluded
// menu.addItem((item) => {
// item.setTitle('Manage excluded folder');
// item.setIcon('settings-2');
// item.onClick(() => {
// if (excludedFolder instanceof ExcludedFolder) {
// new ExcludedFolderSettings(this.plugin.app, this.plugin, excludedFolder).open();
// } else if (excludedFolder instanceof ExcludePattern) {
// new PatternSettings(this.plugin.app, this.plugin, excludedFolder).open();
// }
// });
// if (excludedFolder instanceof ExcludedFolder) {
// new ExcludedFolderSettings(this.plugin.app, this.plugin, excludedFolder).open();
// } else if (excludedFolder instanceof ExcludePattern) {
// new PatternSettings(this.plugin.app, this.plugin, excludedFolder).open();
// }
// });
// });
menu.addItem((item) => {
item.setTitle('Remove folder from excluded folders');
item.setIcon('trash');
item.onClick(() => {
this.plugin.settings.excludeFolders =
this.plugin.settings.excludeFolders.filter(
(excluded) =>
(excluded.path !== file.path) || excluded.detached,
);
this.plugin.saveSettings(true);
new Notice('Successfully removed folder from excluded folders');
});
this.plugin.settings.excludeFolders =
this.plugin.settings.excludeFolders.filter(
(excluded) =>
(excluded.path !== file.path) || excluded.detached,
);
this.plugin.saveSettings(true);
new Notice('Successfully removed folder from excluded folders');
});
});
return;
@ -391,64 +391,64 @@ export class Commands {
item.setTitle('Remove folder from detached folders');
item.setIcon('trash');
item.onClick(() => {
deleteExcludedFolder(this.plugin, detachedExcludedFolder);
});
deleteExcludedFolder(this.plugin, detachedExcludedFolder);
});
});
}
if (detachedExcludedFolder) { return; }
menu.addItem((item) => {
menu.addItem((item) => {
item.setTitle('Exclude folder from folder notes');
item.setIcon('x-circle');
item.onClick(() => {
const newExcludedFolder = new ExcludedFolder(
file.path,
this.plugin.settings.excludeFolders.length,
undefined,
this.plugin,
);
this.plugin.settings.excludeFolders.push(newExcludedFolder);
this.plugin.saveSettings(true);
new Notice('Successfully excluded folder from folder notes');
});
const newExcludedFolder = new ExcludedFolder(
file.path,
this.plugin.settings.excludeFolders.length,
undefined,
this.plugin,
);
this.plugin.settings.excludeFolders.push(newExcludedFolder);
this.plugin.saveSettings(true);
new Notice('Successfully excluded folder from folder notes');
});
});
if (!(file instanceof TFolder)) return;
const folderNote = getFolderNote(this.plugin, file.path);
const folderNote = getFolderNote(this.plugin, file.path);
if (folderNote instanceof TFile && !detachedExcludedFolder) {
if (folderNote instanceof TFile && !detachedExcludedFolder) {
menu.addItem((item) => {
item.setTitle('Delete folder note');
item.setIcon('trash');
item.onClick(() => {
deleteFolderNote(this.plugin, folderNote, true);
});
deleteFolderNote(this.plugin, folderNote, true);
});
});
menu.addItem((item) => {
item.setTitle('Open folder note');
item.setIcon('chevron-right-square');
item.onClick(() => {
openFolderNote(this.plugin, folderNote);
});
openFolderNote(this.plugin, folderNote);
});
});
menu.addItem((item) => {
item.setTitle('Detach folder note');
item.setIcon('unlink');
item.onClick(() => {
detachFolderNote(this.plugin, folderNote);
});
detachFolderNote(this.plugin, folderNote);
});
});
menu.addItem((item) => {
item.setTitle('Copy Obsidian URL');
item.setIcon('link');
item.onClick(() => {
this.app.copyObsidianUrl(folderNote);
});
this.app.copyObsidianUrl(folderNote);
});
});
if (this.plugin.settings.hideFolderNote) {
@ -457,16 +457,16 @@ export class Commands {
item.setTitle('Hide folder note in explorer');
item.setIcon('eye-off');
item.onClick(() => {
hideFolderNoteInFileExplorer(file.path, this.plugin);
});
hideFolderNoteInFileExplorer(file.path, this.plugin);
});
});
} else {
menu.addItem((item) => {
item.setTitle('Show folder note in explorer');
item.setIcon('eye');
item.onClick(() => {
showFolderNoteInFileExplorer(file.path, this.plugin);
});
showFolderNoteInFileExplorer(file.path, this.plugin);
});
});
}
}
@ -475,8 +475,8 @@ export class Commands {
item.setTitle('Create markdown folder note');
item.setIcon('edit');
item.onClick(() => {
createFolderNote(this.plugin, file.path, true, '.md');
});
createFolderNote(this.plugin, file.path, true, '.md');
});
});
this.plugin.settings.supportedFileTypes.forEach((fileType) => {
@ -485,27 +485,27 @@ export class Commands {
item.setTitle(`Create ${fileType} folder note`);
item.setIcon('edit');
item.onClick(() => {
// eslint-disable-next-line max-len
createFolderNote(this.plugin, file.path, true, '.' + fileType);
});
// eslint-disable-next-line max-len
createFolderNote(this.plugin, file.path, true, '.' + fileType);
});
});
});
}
};
};
if (
if (
Platform.isDesktop &&
!Platform.isTablet &&
this.plugin.settings.useSubmenus
) {
menu.addItem(async (item) => {
item.setTitle('Folder Note Commands').setIcon('folder-edit');
let subMenu: Menu = item.setSubmenu() as Menu;
addFolderNoteActions(subMenu);
})
} else {
addFolderNoteActions(menu);
}
) {
menu.addItem(async (item) => {
item.setTitle('Folder Note Commands').setIcon('folder-edit');
let subMenu: Menu = item.setSubmenu() as Menu;
addFolderNoteActions(subMenu);
})
} else {
addFolderNoteActions(menu);
}
}));
}