Rework icons
This commit is contained in:
parent
8549e949dd
commit
b93e472f8d
100
main.ts
100
main.ts
|
@ -20,6 +20,13 @@ const DEFAULT_SETTINGS: ScrapsPluginSettings = {
|
|||
scrapsFileName: "{time DDDD} {A} {N}",
|
||||
};
|
||||
|
||||
const ICON = {
|
||||
New: "file-plus",
|
||||
Convert: "shuffle",
|
||||
Move: "replace",
|
||||
Copy: "copy-plus",
|
||||
} as const;
|
||||
|
||||
async function mkdirp(vault: Vault, folderPath: string): Promise<void> {
|
||||
const pathParts = folderPath.split("/");
|
||||
|
||||
|
@ -77,7 +84,7 @@ export default class ScrapsPlugin extends Plugin {
|
|||
await this.app.workspace.getLeaf(false).openFile(newScrap);
|
||||
}
|
||||
|
||||
async convertToScrap() {
|
||||
async convertToScrap(rename = true) {
|
||||
const currentFile = this.app.workspace.getActiveFile();
|
||||
|
||||
if (currentFile === null) {
|
||||
|
@ -87,45 +94,13 @@ export default class ScrapsPlugin extends Plugin {
|
|||
|
||||
await this.ensureScrapDir();
|
||||
|
||||
await this.app.fileManager.renameFile(
|
||||
currentFile,
|
||||
this.getScrapFilePath()
|
||||
);
|
||||
const filename = rename ? this.getScrapFileName() : currentFile.name;
|
||||
const renamePath = `${this.getScrapDir()}/${filename}`;
|
||||
|
||||
await this.app.fileManager.renameFile(currentFile, renamePath);
|
||||
}
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
this.addSettingTab(new ScrapsSettingTab(this.app, this));
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-new",
|
||||
name: "Scraps: Create new Scrap",
|
||||
icon: "badge-plus",
|
||||
callback: async () => {
|
||||
this.createScrap();
|
||||
},
|
||||
});
|
||||
|
||||
this.addRibbonIcon("badge-plus", "Create new Scrap", async () => {
|
||||
this.createScrap();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-convert",
|
||||
name: "Scraps: Convert current file to Scrap",
|
||||
icon: "file-plus",
|
||||
editorCallback: async () => this.convertToScrap(),
|
||||
});
|
||||
|
||||
this.addRibbonIcon("file-plus", "Convert file to Scrap", async () => {
|
||||
this.convertToScrap();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-copy",
|
||||
name: "Scraps: Copy current file to Scraps",
|
||||
icon: "copy-plus",
|
||||
editorCallback: async () => {
|
||||
async copyToScrap() {
|
||||
const currentFile = this.app.workspace.getActiveFile();
|
||||
|
||||
if (currentFile === null) {
|
||||
|
@ -141,8 +116,57 @@ export default class ScrapsPlugin extends Plugin {
|
|||
);
|
||||
|
||||
await this.app.workspace.getLeaf(false).openFile(newScrap);
|
||||
}
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
this.addSettingTab(new ScrapsSettingTab(this.app, this));
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-new",
|
||||
name: "Scraps: Create new Scrap",
|
||||
icon: ICON.New,
|
||||
callback: async () => {
|
||||
this.createScrap();
|
||||
},
|
||||
});
|
||||
|
||||
this.addRibbonIcon(ICON.New, "Create new Scrap", async () => {
|
||||
this.createScrap();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-convert",
|
||||
name: "Scraps: Convert current file to Scrap",
|
||||
icon: ICON.Convert,
|
||||
editorCallback: async () => this.convertToScrap(),
|
||||
});
|
||||
|
||||
this.addRibbonIcon(ICON.Convert, "Convert file to Scrap", async () => {
|
||||
this.convertToScrap();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-move",
|
||||
name: "Scraps: Move current file to Scraps",
|
||||
icon: ICON.Move,
|
||||
editorCallback: async () => this.convertToScrap(false),
|
||||
});
|
||||
|
||||
this.addRibbonIcon(ICON.Move, "Move file to Scraps", async () => {
|
||||
this.convertToScrap(false);
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
id: "scraps-copy",
|
||||
name: "Scraps: Copy current file to Scraps",
|
||||
icon: ICON.Copy,
|
||||
editorCallback: () => this.copyToScrap(),
|
||||
});
|
||||
|
||||
this.addRibbonIcon(ICON.Copy, "Copy file to Scraps", async () => {
|
||||
this.copyToScrap();
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {}
|
||||
|
|
Loading…
Reference in a new issue