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