mirror of
https://github.com/al0cam/AutoMover.git
synced 2026-07-22 05:41:25 +00:00
added settings tab
This commit is contained in:
parent
4670fdb291
commit
608dded6b5
7 changed files with 2282 additions and 2238 deletions
1
ItemToMove.md
Normal file
1
ItemToMove.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
Nothing much
|
||||
28
Settings/SettingsTab.ts
Normal file
28
Settings/SettingsTab.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import AutoMoverPlugin from "main";
|
||||
import { App, PluginSettingTab, Setting } from "obsidian";
|
||||
|
||||
export class SettingsTab extends PluginSettingTab{
|
||||
plugin: AutoMoverPlugin;
|
||||
|
||||
constructor(app: App, plugin: AutoMoverPlugin) {
|
||||
super(app, plugin);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
display(): void {
|
||||
let { containerEl } = this;
|
||||
|
||||
containerEl.empty();
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName("Move on open")
|
||||
.setDesc("Should the file be moved when it is opened?")
|
||||
.addToggle(cb => cb
|
||||
.setValue(this.plugin.settings.moveOnOpen)
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.moveOnOpen = value;
|
||||
await this.plugin.saveData(this.plugin.settings);
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@ class MovingUtil {
|
|||
}
|
||||
|
||||
public isFile(path: string): boolean {
|
||||
let something = this.app.vault.getAbstractFileByPath(path);
|
||||
return this.app.vault.getAbstractFileByPath(path) instanceof TFile;
|
||||
}
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ class MovingUtil {
|
|||
return this.app.vault.getAbstractFileByPath(path) instanceof TFolder;
|
||||
}
|
||||
|
||||
|
||||
public moveFile(file: TFile, newPath: string): void {
|
||||
if(this.isFolder(newPath)) {
|
||||
this.app.vault.rename(file, newPath + "/" + file.name);
|
||||
|
|
@ -43,7 +45,6 @@ class MovingUtil {
|
|||
console.error("Invalid destination path\n" + newPath + "is not a folder!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const movingUtil = MovingUtil.getInstance();
|
||||
|
|
|
|||
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
22
main.ts
22
main.ts
|
|
@ -1,5 +1,6 @@
|
|||
import { Plugin } from "obsidian";
|
||||
import { Plugin, TFile } from "obsidian";
|
||||
import { AutoMoverSettings, DEFAULT_SETTINGS } from "Settings/Settings";
|
||||
import { SettingsTab } from "Settings/SettingsTab";
|
||||
import movingUtil from "Utils/MovingUtil";
|
||||
|
||||
export default class AutoMoverPlugin extends Plugin {
|
||||
|
|
@ -8,12 +9,25 @@ export default class AutoMoverPlugin extends Plugin {
|
|||
async onload() {
|
||||
console.log('loading plugin')
|
||||
movingUtil.init(this.app);
|
||||
console.log(movingUtil.isFile("Untitled.md"));
|
||||
console.log(movingUtil.isFolder("Untitled.md"));
|
||||
console.log("CANCER");
|
||||
|
||||
// create file
|
||||
// let newFile: TFile;
|
||||
// if(this.app.vault.getAbstractFileByPath("Something.md") === null) {
|
||||
// newFile = await this.app.vault.create("./Something.md", "This is a test file")
|
||||
// } else {
|
||||
// newFile = this.app.vault.getAbstractFileByPath("Something.md") as TFile;
|
||||
// }
|
||||
// delete file
|
||||
// await this.app.vault.delete(this.app.vault.getAbstractFileByPath("amFolder/Something.md") as TFile);
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
this.addSettingTab(new SettingsTab(this.app, this));
|
||||
console.log(this.settings);
|
||||
}
|
||||
|
||||
asyncloadSettings() {
|
||||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||
}
|
||||
|
||||
async onunload() {
|
||||
console.log('unloading plugin')
|
||||
}
|
||||
|
|
|
|||
4422
package-lock.json
generated
4422
package-lock.json
generated
File diff suppressed because it is too large
Load diff
44
package.json
44
package.json
|
|
@ -1,24 +1,24 @@
|
|||
{
|
||||
"name": "obsidian-sample-plugin",
|
||||
"version": "1.0.0",
|
||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "0.17.3",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
}
|
||||
"name": "obsidian-sample-plugin",
|
||||
"version": "1.0.0",
|
||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"version": "node version-bump.mjs && git add manifest.json versions.json",
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "0.17.3",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue